3074. 特殊加密

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<>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;
}

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