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.
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
1 #include"stdio.h" 2 #include"string.h" 3 int main(void) 4 { 5 char fr[10]="START",end[10]="END",main[1000]; 6 int len,i; 7 while(scanf("%s",fr)!=EOF&&strcmp(fr,"ENDOFINPUT")!=0) 8 { 9 getchar(); //輸入段 10 gets(main); 11 scanf("%s",end); 12 13 len=strlen(main); //處理段 14 for(i=0;i<len;i++) 15 { 16 if(main[i]>'Z' || main[i]<'A') continue; 17 if(main[i]>'E') main[i]=main[i]-5; 18 else main[i]='Z'-(5-main[i]+'A')+1; 19 } 20 for(i=0;i<len;i++) //輸出段,puts()應該也可以 21 printf("%c",main[i]); 22 printf("\n"); 23 } 24 return 0; 25 }
這段代碼我寫了兩個小時,不要笑我(很不開心),最開始的算法完全是錯的,因為我的思路裡,把 "END" 忽略了,發現的時候就比較麻煩了,而且關於 puts() , %s的語法在換行方面的處理不太清楚,C語言只是一種語言,但其他語言在換行字符上的糾結,我覺的以後在我的學習之路上也應該留意下。
在字符組的使用裡,尤其要注意字符組長度,一定要略大於需要長度,而且要注意對 '\0' 結束符的處理(這點是最煩人的)。
至於 1048 的解題思路就不細說了,真的是一道水題,看代碼吧