hdu1048

The Hardest Problem Ever

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15093    Accepted Submission(s): 6981


Problem Description
Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked. 
You are a sub captain of Caesar's army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is 'A', the cipher text would be 'F'). Since you are creating plain text out of Caesar's messages, you will do the opposite: 

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 

Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
 

Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase. 

A single data set has 3 components: 

Start line - A single line, "START" 

Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar 

End line - A single line, "END" 

Following the final data set will be a single line, "ENDOFINPUT".
 

Output
For each data set, there will be exactly one line of output. This is the original message by Caesar.
 

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
 

Source
#include<stdio.h>
#include<string.h>
int main()
{
    char ch[202];
    int i;
    while(gets(ch))//关键是输入如何处理  
    {
        if(strcmp(ch,"START")==0)  continue;
        if(strcmp(ch,"END")==0)    continue;
        if(strcmp(ch,"ENDOFINPUT")==0)  break;
        for(i=0;i<strlen(ch);i++)
        {
            if(ch[i]>='A'&&ch[i]<='Z')
              printf("%c",((ch[i]-5<'A')?(ch[i]+21):(ch[i]-5)));
            else
              printf("%c",ch[i]);
        }
        printf("\n");
    }
    return 0;
}

熟悉字符串函数       gets()   可以输入一段有空格的字符串
                                  scanf     输入 有空格的要隔开
                             
strcpy
  原型:extern char *strcpy(char *dest,char *src);
        
  用法:#include <string.h>
  
  功能:把src所指由NULL结束的字符串复制到dest所指的数组中。
  
  说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
        返回指向dest的指针。
  
  举例:


      // strcpy.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s="Golden Global View";
        char d[20];
        
        clrscr();
        
        strcpy(d,s);
        printf("%s",d);

        getchar();
        return 0;
      }
strncpy
  原型:extern char *strncpy(char *dest, char *src, int n);
        
  用法:#include <string.h>
  
  功能:把src所指由NULL结束的字符串的前n个字节复制到dest所指的数组中。
  
  说明:
        如果src的前n个字节不含NULL字符,则结果不会以NULL字符结束。
        如果src的长度小于n个字节,则以NULL填充dest直到复制完n个字节。
        src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
        返回指向dest的指针。
  
  举例:


      // strncpy.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s="Golden Global View";
        char *d="Hello, GGV Programmers";
        char *p=strdup(s);
        
        clrscr();
        textmode(0x00);  // enable 6 lines mode
                
        strncpy(d,s,strlen(s));
        printf("%s\n",d);
        
        strncpy(p,s,strlen(d));
        printf("%s",p);
        

        getchar();
        return 0;
      }
strcmp
  原型:extern int strcmp(char *s1,char * s2);
        
  用法:#include <string.h>
  
  功能:比较字符串s1和s2。
  
  说明:
        当s1<s2时,返回值<0
        当s1=s2时,返回值=0
        当s1>s2时,返回值>0
  
  举例:

      // strcmp.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s1="Hello, Programmers!";
        char *s2="Hello, programmers!";
        int r;
        
        clrscr();
        
        r=strcmp(s1,s2);
        if(!r)
          printf("s1 and s2 are identical");
        else
        if(r<0)
          printf("s1 less than s2");
        else
          printf("s1 greater than s2");
        

        getchar();
        return 0;
      }
stricmp,strcmpi
  原型:extern int stricmp(char *s1,char * s2);
        
  用法:#include <string.h>
  
  功能:比较字符串s1和s2,但不区分字母的大小写。
  
  说明:strcmpi是到stricmp的宏定义,实际未提供此函数。
        当s1<s2时,返回值<0
        当s1=s2时,返回值=0
        当s1>s2时,返回值>0
  
  举例:

      // stricmp.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s1="Hello, Programmers!";
        char *s2="Hello, programmers!";
        int r;
        
        clrscr();
        
        r=stricmp(s1,s2);
        if(!r)
          printf("s1 and s2 are identical");
        else
        if(r<0)
          printf("s1 less than s2");
        else
          printf("s1 greater than s2");
        

        getchar();
        return 0;
      }

strnicmp,strncmpi
  原型:extern int strnicmp(char *s1,char * s2,int n);
        
  用法:#include <string.h>
  
  功能:比较字符串s1和s2的前n个字符但不区分大小写。
  
  说明:strncmpi是到strnicmp的宏定义
        当s1<s2时,返回值<0
        当s1=s2时,返回值=0
        当s1>s2时,返回值>0
  
  举例:

      // strnicmp.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s1="Hello, Programmers!";
        char *s2="Hello, programmers!";
        int r;
        
        clrscr();
        
        r=strnicmp(s1,s2,strlen(s1));
        if(!r)
          printf("s1 and s2 are identical");
        else
        if(r<0)
          printf("s1 less than s2");
        else
          printf("s1 greater than s2");
        
        getchar();
        return 0;
      }

strcat
  原型:extern char *strcat(char *dest,char *src);
        
  用法:#include <string.h>
  
  功能:把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'。
  
  说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
        返回指向dest的指针。
  
  举例:


      // strcat.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char d[20]="Golden Global";
        char *s=" View";
        
        clrscr();
        
        strcat(d,s);
        printf("%s",d);

        getchar();
        return 0;
      }
strncat
  原型:extern char *strncat(char *dest,char *src,int n);
        
  用法:#include <string.h>
  
  功能:把src所指字符串的前n个字符添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'。
  
  说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
        返回指向dest的指针。
  
  举例:


      // strncat.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char d[20]="Golden Global";
        char *s=" View WinIDE Library";
        
        clrscr();
        
        strncat(d,s,5);
        printf("%s",d);

        getchar();
        return 0;
      }
      
strchr
  原型:extern char *strchr(char *s,char c);
        
  用法:#include <string.h>
  
  功能:查找字符串s中首次出现字符c的位置
  
  说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。
  
  举例:


      // strchr.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s="Golden Global View";
        char *p;
        
        clrscr();
        
        strchr(s,'V');
        if(p)
          printf("%s",p);
        else
          printf("Not Found!");

        getchar();
        return 0;
      }
      
strupr
  原型:extern char *strupr(char *s);
        
  用法:#include <string.h>
  
  功能:将字符串s转换为大写形式
  
  说明:只转换s中出现的小写字母,不改变其它字符。返回指向s的指针。
  
  举例:


      // strupr.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s="Copywrite 1999-2000 GGV Technologies";
        
        clrscr();
        
        printf("%s",strupr(s));

        getchar();
        return 0;
      }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值