zoukankan      html  css  js  c++  java
  • 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"

    解题思路: 字符串末尾没有加'' 导致我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] = '';
    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] = '';
    65 
    66 
    67 
    68             for(i = k-1; i > -1; i--)
    69                 printf("%c", G[i]);
    70             printf("
    ");
    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]='';
    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] = '';
    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] = '';
    72 
    73             for(i = k-1; i > -1; i--)
    74                 printf("%c", G[i]);
    75             printf("
    ");
    76         }
    77         return 0;
    78     }
  • 相关阅读:
    C语言 选择排序算法原理和实现 从数组中 找出最小的元素然后交换位置
    C语言十六进制转换成十进制:要从右到左用二进制的每个数去乘以16的相应次方
    pycharm的注册码,所有版本
    无法链接glew的解决办法-编译开源库出现: error LNK2001: 无法解析的外部符号
    删除文件是遇到“拒绝访问”的解决方法
    基类的析构函数写成virtual虚析构函数
    C++语言定义的标准转换
    VC中C++数值范围的确定
    SCI投稿过程总结、投稿状态解析、拒稿后对策及接受后期相关问答
    STL其他--<tuple>用法【C11】
  • 原文地址:https://www.cnblogs.com/firstrate/p/3196963.html
Copyright © 2011-2022 走看看