SZU:G34 Love code

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 :

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdio.h>
 4 
 5 char M[10][7] = {"/-----","/*----","/**---","/***--","/****-","/*****","/-****","/--***","/---**","/----*"};
 6 char N[10][5]={"","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
 7 char s[5012];
 8 char A[100];
 9 int B[1012];
10 char C[26];
11 char D[40];
12 char T[40];
13 char E[20];
14 char F[20];
15 char G[40];
16 
17 
18 
19 int main() {
20     int t,i,k,j, len;
21     scanf("%d", &t);
22     getchar();
23     strcpy(C,"QWERTYUIOPASDFGHJKLZXCVBNM");
24 
25     while (t--) {
26         scanf("%s", s);
27         len = strlen(s);
28         for (i=0;i<len;i+=6) {
29             j=i;
30             k=0;
31             while (k<6)
32                 A[k++] = s[j++];
33             A[6] = '\0';
34             for(j=0;j<10;j++) if(strcmp(A,M[j])==0) break;
35                 B[i/6] = j;
36         }
37 
38         for(i=0;i<len/12;++i){
39             T[i]=N[B[2*i]][B[2*i+1]-1];
40         }
41 
42         k=i;
43 
44     for(i=0;i<k;i++){
45 
46             for(j=0;j<26;++j)
47                 if(T[i]==C[j]){
48                     T[i]=('A'+j);
49                     break;
50                 }
51             }
52 
53 
54             j=0;
55             for(i=0; i<(k-1)/2+1; i++) {
56                 G[j] = T[i];
57                 j+=2;
58             }
59             j=1;
60             for(i=(k-1)/2+1; i<k; i++) {
61                 G[j] = T[i];
62                 j+=2;
63             }
64             G[k] = '\0';
65 
66 
67 
68             for(i = k-1; i > -1; i--)
69                 printf("%c", G[i]);
70             printf("\n");
71     }
72     return 0;
73 }

dd 帮我调试的代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdio.h>
 4 
 5 char M[10][7] = {"-----","*----","**---","***--","****-","*****","-****","--***","---**","----*"};
 6 char N[10][6]={"",""," ABC"," DEF"," GHI"," JKL"," MNO"," PQRS"," TUV"," WXYZ"};
 7 char s[5012];
 8 char A[100];
 9 int B[1012];
10 char C[260];
11 char D[200];
12 char T[400];
13 char E[200];
14 char F[200];
15 char G[400];
16 
17 
18 int main() {
19     int t,i,k,j, len;
20     scanf("%d", &t);
21     getchar();
22     strcpy(C,"QWERTYUIOPASDFGHJKLZXCVBNM");
23 
24     while (t--) {
25         scanf("%s", s);
26         len = strlen(s);
27         for(i = 0; i < len; i++)
28             if(s[i] == '/')
29                 break;
30         int e = 0;
31         for (i++; i<len;i+=6) {
32             j=i;
33             k=0;
34 
35             strcpy(A, "");
36             strncpy(A,&s[i],5);
37             A[5]='\0';
38 
39 
40             for(j=0;j<10;j++) if(strcmp(A,M[j])==0) break;
41                 B[e++] = j;
42         }
43 
44         k = 0;
45         for(i=0; i<e; i+=2)
46             T[k++] = N[B[i]][B[i+1]];
47         T[k] = '\0';
48 
49         for(i=0;i<k;i++){
50 
51             for(j=0;j<26;++j)
52                 if(T[i]==C[j]){
53                     T[i]=('A'+j);
54                     break;
55                 }
56         }
57 
58             e = 0;
59             for(i=0;i<(k-1)/2+1;i++){
60                 //E[i]=T[i];
61                 G[e] = T[i];
62                 e+=2;
63             }
64 
65             e = 1;
66             for(i=(k-1)/2+1;i<k;i++){
67                 //F[j++]=T[i];
68                 G[e] = T[i];
69                 e+=2;
70             }
71             G[e] = '\0';
72 
73             for(i = k-1; i > -1; i--)
74                 printf("%c", G[i]);
75             printf("\n");
76         }
77         return 0;
78     }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值