3074. 特殊加密

computerLearner

写我的笨笨方法

#include<iostream>
#include<map>
#include<string>
#include<cstring>
using namespace std;

map<char, int>m1;

void speakout(int n){
    if(n == 0)
        cout << "-----";
    if(n == 1)
        cout << ".----";
    if(n ==2)
        cout << "..---";
    if(n == 3)
        cout << "...--";
    if(n == 4)
        cout << "....-";
    if(n == 5)
        cout << ".....";
    if(n == 6)
        cout << "-....";
    if(n == 7)
        cout << "--...";
    if(n == 8)
        cout << "---..";
    if(n ==9)
        cout << "----.";
}

int main(){
    m1['A'] = 21;
    m1['B'] = 22;
    m1['C'] = 23;
    m1['D'] = 31;
    m1['E'] = 32;
    m1['F'] = 33;
    m1['G'] = 41;
    m1['H'] = 42;
    m1['I'] = 43;
    m1['J'] = 51;
    m1['K'] = 52;
    m1['L'] = 53;
    m1['M'] = 61;
    m1['N'] = 62;
    m1['O'] = 63;
    m1['P'] = 71;
    m1['Q'] = 72;
    m1['R'] = 73;
    m1['S'] = 74;
    m1['T'] = 81;
    m1['U'] = 82;
    m1['V'] = 83;
    m1['W'] = 91;
    m1['X'] = 92;
    m1['Y'] = 93;
    m1['Z'] = 94;
    int times;
    cin >> times;
    for(int i = 0; i < times; i++){

        string str;
        cin >> str;
        cout << "case #" << i <<":" << endl;
        for(int j = 0; j < str.size(); j++){
            int k = m1.at(str[j]);


            int last = k % 10;
            int first= k / 10;

            speakout(first);
            cout << '/';
            speakout(last);
            if(j != str.size()-1)
            cout << '/';

        }
        cout << endl;

    }


}
shwei
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string code[10] = {"-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",};
vector <int> stringtoint(string s) {
    vector <int> res;
    for (int k = 0; k < s.size(); k++) {
        int i = s[k] - 65;
        int first, second;
        if (i >= 0 && i < 15) {
            first = i / 3 + 2;
            second = i % 3 + 1;
        } else if (i >= 15 && i < 19) {
            first = 7;
            second = i - 15 + 1;
        } else if (i >= 19 && i < 22) {
            first = 8;
            second = i - 19 + 1;
        } else {
            first = 9;
            second = i - 22 + 1;
        }
        res.push_back(first);
        res.push_back(second);
    }
    return res;
}

int main(void) {
    #ifdef LC
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif


    int T, cnt = 0;
    cin >> T;
    while (T--) {
        //1: 输入数据
                string s;
                cin >> s;
        //2核心算法
        vector <int> tmp = stringtoint(s);

        //3: 输出结果
        cout << "case #" << cnt << ":\n";
        cnt++;
        for (int i = 0; i < tmp.size() - 1; i++) {
            cout << code[tmp[i]] << "/";
        }
        cout << code[tmp[tmp.size() - 1]];
        cout << endl;

    }
    return 0;
}
Li Dao

试着学会使用常量数组简化程序

include

using namespace std;
const int toint[26]={21,22,23,31,32,33,41,42,43,51,52,53,61,62,63,71,72,73,74,81,82,83,91,92,93,94};
const string tocode[10]={“-----“,”.----“,”..—“,”…–“,”....-“,”.....”,”-....”,”–…”,”—..”,”----.”};
int T;
void print(char aa)
{
int index=toint[aa-‘A’];
cout<<tocode[index/10];
cout<<”/”<>line;
int ll=line.length();
int first=1;
for(int i=0;i<ll;i++)
{
if(first) first=0; else cout<<”/”;
print(line[i]);
}
cout<<endl;
return;
}

int main()
{
scanf(“%d”,&T);
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}

你当前正在回复 博客/题目
存在问题!