您的位置:首页 > 其它

SZU:G34 Love code

2013-07-17 21:59 148 查看

Judge Info

Memory Limit: 32768KB

Case Time Limit: 10000MS

Time Limit: 10000MS

Judger: Normal

Description

A boy and a girl both like studying code in their extra-curricular. Of course, they like each other. Therefore, the boy shows his love to the girl one day. The girl smiles and leaves a series of Morse code. After 5 times of decoding, the boy will get the answer. The boy makes his best efforts but 5 times of decoding is almost impossible. He has no choice but to ask for help on the Internet. He posts his troublesome on baidu tieba. Everyone is eager to help him. And after 6 hours, miracle happens. The boy get his answer. Beside deeply moved, the author also hope you can show him this romantic again. We will tell you the 5 times of encryption and the decoded words. We want you to tell us the original code. We suppose the original code is:

/****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/

1. Using Morse code, we can transform the original code into number. Every '/' separates a number.

We will get a number list.

41 94 41 81 41 63 41 92 62 23 74

2. B. Using these numbers, in the keyboard of cell phone, we will decorate 26 letters on the key 2-9 so that we can use two numbers to get one letter. Such as 63 means the number 6 key, the 3th letter. It’s ‘O’.

The number list became a letter string

G Z G T G O G X N C S

3. Continue to our transformation, we use our computer keyboards this time. Our familiar keyboard often arranges letters in the order of "QWERTY...”. So we suppose 'Q' to 'A','W' to 'B' ..'G' to 'O'..at last 'M' to 'Z'.

The new code is

O T O E O I O U Y V L

4. We will soon get the answer after the last two steps. Are you eager to know it? This time is barrier transforming. We cut the original code into the former part and the after part. If the length of the code is odd, the former part is allowed to have one more letter than the after part. Then, put every letters of the after part into every interval of the former part. After cutting the code, we get "O T O E O I ","O U Y V L". Then after putting them alternately, we get

O O T U O Y E V O L I.

5. Clever as you, have you get the answer? If we output the strings in reverse order, we can see the simple and pure romance.

ILOVEYOUTOO (I Love You Too!)


Input

The first line is an integer t ,means the number of test cases. The next t lines, each has a string as the test data.

Output

Output the original code. (the answer won’t be longer than 30 character.)

Sample Input

/****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/


Sample Output

ILOVEYOUTOO


Hint

Morse code table (number part)
0 -----  5 *****
1 *----  6 -****
2 **---  7 --***
3 ***--  8 ---**
4 ****-  9 ----*

cell phone keyboard character table
2.abc    3.def
4.ghi    5.jkl
6.mno    7.pqrs
8.tuv    9.wxyz

computer keyboard order table
"QWERTYUIOPASDFGHJKLZXCVBNM"


解题思路: 字符串末尾没有加'\0' 导致我4个小时调试,找大神才解决。

code :

#include <stdio.h>
#include <string.h>
#include <stdio.h>

char M[10][7] = {"/-----","/*----","/**---","/***--","/****-","/*****","/-****","/--***","/---**","/----*"};
char N[10][5]={"","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
char s[5012];
char A[100];
int B[1012];
char C[26];
char D[40];
char T[40];
char E[20];
char F[20];
char G[40];

int main() {
int t,i,k,j, len;
scanf("%d", &t);
getchar();
strcpy(C,"QWERTYUIOPASDFGHJKLZXCVBNM");

while (t--) {
scanf("%s", s);
len = strlen(s);
for (i=0;i<len;i+=6) {
j=i;
k=0;
while (k<6)
A[k++] = s[j++];
A[6] = '\0';
for(j=0;j<10;j++) if(strcmp(A,M[j])==0) break;
B[i/6] = j;
}

for(i=0;i<len/12;++i){
T[i]=N[B[2*i]][B[2*i+1]-1];
}

k=i;

for(i=0;i<k;i++){

for(j=0;j<26;++j)
if(T[i]==C[j]){
T[i]=('A'+j);
break;
}
}

j=0;
for(i=0; i<(k-1)/2+1; i++) {
G[j] = T[i];
j+=2;
}
j=1;
for(i=(k-1)/2+1; i<k; i++) {
G[j] = T[i];
j+=2;
}
G[k] = '\0';

for(i = k-1; i > -1; i--)
printf("%c", G[i]);
printf("\n");
}
return 0;
}


dd 帮我调试的代码:

#include <stdio.h>
#include <string.h>
#include <stdio.h>

char M[10][7] = {"-----","*----","**---","***--","****-","*****","-****","--***","---**","----*"};
char N[10][6]={"",""," ABC"," DEF"," GHI"," JKL"," MNO"," PQRS"," TUV"," WXYZ"};
char s[5012];
char A[100];
int B[1012];
char C[260];
char D[200];
char T[400];
char E[200];
char F[200];
char G[400];

int main() {
int t,i,k,j, len;
scanf("%d", &t);
getchar();
strcpy(C,"QWERTYUIOPASDFGHJKLZXCVBNM");

while (t--) {
scanf("%s", s);
len = strlen(s);
for(i = 0; i < len; i++)
if(s[i] == '/')
break;
int e = 0;
for (i++; i<len;i+=6) {
j=i;
k=0;

strcpy(A, "");
strncpy(A,&s[i],5);
A[5]='\0';

for(j=0;j<10;j++) if(strcmp(A,M[j])==0) break;
B[e++] = j;
}

k = 0;
for(i=0; i<e; i+=2)
T[k++] = N[B[i]][B[i+1]];
T[k] = '\0';

for(i=0;i<k;i++){

for(j=0;j<26;++j)
if(T[i]==C[j]){
T[i]=('A'+j);
break;
}
}

e = 0;
for(i=0;i<(k-1)/2+1;i++){
//E[i]=T[i];
G[e] = T[i];
e+=2;
}

e = 1;
for(i=(k-1)/2+1;i<k;i++){
//F[j++]=T[i];
G[e] = T[i];
e+=2;
}
G[e] = '\0';

for(i = k-1; i > -1; i--)
printf("%c", G[i]);
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: