字元轉換

 avatar
user_3763047219
c_cpp
2 years ago
606 B
3
Indexable
Never
#include <stdio.h>
int main()
{
	int num, abcnum;
	char addmin, abc,abc2;
	scanf("%c%d%c", &addmin,&num,&abc);
	char abcstr[26] = { 'A','B','C','D','E','F','G','H','I','J','K',
					 'L','M','N','O','P','Q','R','S','T','U',
					 'V','W','X','Y','Z' };

	for (int i = 0;i < 26;i++) {
		if (abc == abcstr[i]) {
			abcnum = i+1;
		}
	}
	if (addmin == '+') {
		printf("%c",abcstr[(abcnum + num) % 26 - 1]);
	}
	else if (addmin == '-') {
		if (abcnum > num) {
			printf("%c", abcstr[(abcnum - num) % 26 - 1]);
		}
		else if (abcnum < num) {
			printf("%c", abcstr[26-((-1)*(abcnum - (num+1)) % 26) ]);
		}
	}
}