网站模板 北京公司企业网站搜索优化网络推广
简单编码
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description
将一串文本译成密码,密码的规律是:
将原来的小写字母全部翻译成大写字母,大写字母全部翻译成小写字母,数字的翻译规律如下:
0——>9
1——>8
2——>7
3——>6
4——>5
5——>4
6——>3
7——>2
8——>1
9——>0
然后将所有字符的顺序颠倒。
Input
输入一串文本,最大字符个数不超过100。
Output
输出编码后的结果。
Sample Input
china
Sample Output
ANIHC
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{int i, len;char a[110];memset(a, 0, sizeof(a));gets(a);//别忘记输入!!1len = strlen(a);//计算字符串a的长度,用来控制循环次数for(i = 0; i < len; i++){if(a[i] >= 'a' && a[i] <= 'z'){a[i] -= 32;}else if(a[i] >= 'A' && a[i] <= 'Z'){a[i] += 32;}else if(a[i] >= '0' && a[i] <= '9'){a[i] = '9' - a[i] + '0';//此处要注意!难点!}//以0举例,0的ascll码为48,9的为57,57-48=9,//所求数字为9,则需要加上48的ascll码}for(i = len - 1; i >= 0; i--){//倒序输入,此处注意一开始是(i = len - 1),最后一个字符是(i = 0)printf("%c", a[i]);}return 0;
}