题意:给出一个字母对应符号的表格,然后输入是一串符号,要求输出对应的字母。
思路:水题,用数组记录下比对下就好了。
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<utility>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
char ch[1010];
char alph[26][5] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%s", ch) != EOF){
char tmp[10];
int p=0;
int len = strlen(ch);
int t=0;
while(t<len){
if(ch[t]!='/'){
tmp[p++] = ch[t++];
}
else if(ch[t] == '/'){
if(p == 0){
printf(" ");
}
else{
tmp[p] = '\0';
for(int i=0; i<26; i++){
if(strcmp(tmp, alph[i]) == 0){
printf("%c", i+'A');
p = 0;
break;
}
}
}
t++;
}
if(t == len){
tmp[p] = '\0';
//printf("tmp = %s\n", tmp);
for(int i=0; i<26; i++){
if(strcmp(tmp, alph[i]) == 0){
printf("%c", i+'A');
p = 0;
break;
}
}
}
}
printf("\n");
}
return 0;
}