zoukankan      html  css  js  c++  java
  • HDU 1048 The Hardest Problem Ever

    原题大意:

    给出相应的密码本,将密文字母按照所给密码本列出的对应关系解密,字母均为大写,对于非大写字母则同密文保持一致,即不用翻译原样输出。

    密码本:Cipher text(密文)A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

    Plain text  (明文)V W X Y Z A B C D E F G H I J K L M N O P Q R S T U 

    输入:

    每个密文由3部分组成:起始行---标记为“START”;密文Cipher message;结束行---标记为“END”。

    输出:

    对于每个密文,将其按照密码本破译为明文。 

    Sample Input
    START
    NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX
    END
    START
    N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
    END
    START
    IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
    END
    ENDOFINPUT
    Sample Output
    IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
    I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
    DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE

    解法一:

     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int main()
     5 {
     6     char cipher[1024];
     7     int i;
     8     while(1)
     9     {
    10         gets(cipher);
    11         if(strcmp("ENDOFINPUT",cipher) == 0)
    12         {
    13             break;
    14         }
    15         if(strcmp(cipher,"START") == 0 || strcmp(cipher,"END") == 0)
    16         {
    17             continue;
    18         }
    19         for(i = 0;i < strlen(cipher); ++i)
    20         {
    21             if(cipher[i] >= 'F' && cipher[i] <= 'Z')
    22             {
    23                 cipher[i] -= 5; 
    24             }
    25             else if(cipher[i] >= 'A' && cipher[i] <= 'E')
    26             {
    27                 cipher[i] += 21;
    28             }
    29             printf("%c",cipher[i]);
    30         }
    31         printf("\n");
    32     }
    33     return 0;
    34 }
    Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author
    7716920 2013-03-08 23:25:34 Accepted 1048 0MS 228K 540 B GCC whseay
    解法二:
     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {  
     5     char alpha[]="VWXYZABCDEFGHIJKLMNOPQRSTU";
     6     char str[1024];
     7     int i,len;
     8     while(gets(str))
     9     {
    10         if(strcmp(str, "ENDOFINPUT") == 0)
    11         {
    12             break;    
    13         }
    14         if(strcmp(str, "START") != 0 && strcmp(str, "END") != 0)
    15         {
    16             len = strlen(str);
    17             for(i = 0;i < len; i++)
    18             {
    19                 if(str[i] >= 'A' && str[i] <= 'Z')
    20                    printf("%c",alpha[str[i] - 'A']);
    21                 else
    22                    printf("%c",str[i]);
    23             } 
    24             printf("\n");   
    25         }    
    26     }
    27     return 0;    
    28 } 
    Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author
    7717337 2013-03-09 00:48:49 Accepted 1048 0MS 228K 628 B GCC whseay
  • 相关阅读:
    词法分析程序
    大数据概述作业
    编译原理心得
    简化C语言文法
    解决:eclipse引入一个新项目所有jsp报错
    解决: 启动tomcat java.net.BindException: Address already in use: JVM_Bind错误
    myeclipse优化
    jquery冲突
    QQ上传大文件为什么这么快
    java中的重写和重载
  • 原文地址:https://www.cnblogs.com/whseay/p/2951633.html
Copyright © 2011-2022 走看看