HDU's ACM 1048 The Hardest Problem Ever

原題鏈接:HDU’s ACM 1048 The Hardest Problem Ever


分析:讀入輸出,就是這樣。小小的技巧就是可以藉助字符數組實現字符變換。


AC Code:

<span style="font-family:Microsoft YaHei;font-size:14px;">#include <stdio.h>
#include <string.h>

#define MAXA 10+5
#define MAXB 200+10

char A[MAXA];
char B[MAXB];

const character[26] = {'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()
{
	int i;
	while(gets(A)) {
		if(strcmp(A, "START") == 0)
			memset(B, 0, sizeof(B));
		else if(strcmp(A, "END") == 0)
			printf("%s\n", B);
		else if(strcmp(A, "ENDOFINPUT") == 0)
			break;
		else {
			for(i=0;A[i] != '\0';++i){
				if(A[i]>='A' && A[i]<='Z')
					B[i] = character[A[i]-'A'];
				else
					B[i] = A[i];
			}
		}
	}
	return 0;
}</span>


点赞