1. 程式人生 > >7-1 字串替換 (15 分)

7-1 字串替換 (15 分)

本題要求編寫程式,將給定字串中的大寫英文字母按以下對應規則替換: 原字母 對應字母 A Z B Y C X D W … … X C Y B Z A 輸入格式:

輸入在一行中給出一個不超過80個字元、並以回車結束的字串。 輸出格式:

輸出在一行中給出替換完成後的字串。 輸入樣例:

Only the 11 CAPItaL LeTtERS are replaced.

輸出樣例:

Lnly the 11 XZKRtaO OeGtVIH are replaced.

#include<stdio.h>
#include<string.h>
int main()
{
	char str[100];
	int len;
	gets(str);
	len=strlen(str);
	int i=0;
	for(int i=0;i<len;i++)
	{
		if(str[i]>='A' && str[i]<='Z')
		{
			char a=str[i];
			int b=a-'A';
			str[i]='A'+'Z'-a;
		}
	}
	puts(str);
	return 0;
}