poj 1298 The Hardest Problem Ever
題目是很水的,要注意兩點,一個就是字符串必須比放入的數組多一個,如這道題strlen(a)=26,sizeof(a)=27。。。
還有一點就是gets()函數可以輸入空格,不能輸入回車,但是s%不能輸入空格,也不能輸入回車
AC的代碼:
#include <stdio.h>
#include <string.h>
char a[27] = {'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'};
int main()
{
//freopen("test.txt","r",stdin);
char Input[1000];
while(gets(Input))
{
if(strcmp(Input,"ENDOFINPUT")==0)
return 0;
else if(strcmp(Input,"START")==0 || strcmp(Input,"END")==0)
continue;
for(int i=0;i<strlen(Input);i++)
{
if (Input[i]>=65 && Input[i]<=90)
printf("%c",a[Input[i]-65]);
else
printf("%c",Input[i]);
}
printf("\n");
}
return 0;
}
最後更新:2017-04-03 14:53:53