连续输入一批以 # 结束的字符串(字符串的长度不超过80),遇 ## 则全部输入结束。
将每个字符串中的大写字母用下面列出的对应大写字母替换, 其余字符不变, 输出替换后的字符串.
原字母   对应字母
   A ──→ Z
   B ──→ Y
   C ──→ X
   D ──→ W
      ……
   X ──→ C
   Y ──→ B
   Z ──→ A
例:括号内是说明
输入:
A flag of USA#IT12#oueiaba##   (连续输入3个字符串)
输出:
Z flag of FHZ
RG12
oueiaba

#include "stdio.h"
#include "string.h"
#define MAXLEN 80
int main( )
{  int i,k;
  char ch,oldch,str[MAXLEN];
  oldch=' ';
  while((ch=getchar())!='#'||oldch!='#'){
     k=0;
     while(ch!='#'&& k< MAXLEN-1){
       str[k++]=ch;
       ch=getchar();
     }
     oldch='#';
     str[k]='\0';
    for(i=0;i<k;i++)
      if(str[i]>='A'&&str[i]<='Z')
        str[i]='Z'-(str[i]-'A');
     puts(str);
  }
}
Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(213)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember