68 请给我加密

68 请给我加密

作者: 朱星垠时间限制: 1S章节: 字符串

问题描述 :

编写一个加密程序,将一个英文句子加密后输出。加密译码规则为: 

1.由键盘输入英文句子和密钥M(0≤M≤50); 

2.将其中的英文字符都变为大写,用数字1..26 分别代表A..Z并加上密钥M后输出; 

3.将其中的空格用数字‘0’输出; 

4.其它符号则变成其ASCII序号加上100输出; 

5.输出的数字之间用空格分隔。

输入说明 :

你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。 

第一行输入为输入数据的组数n。 

每组输入包括两行,第一行为英文原句,可能包含一个或多个空格,第二行为密钥M(0≤M≤50),M为整数。

输出说明 :

对应每组输入你的程序需要向标准输出设备(通常为启动该程序的终端)依次输出一组(一行)对应的答案:一行加密后的句子,中间以一个空格隔开,行首行尾无空格。两组之间无空行。

输入范例 :

2
i love acm!
35
accepted
40

输出范例 :

44 0 47 50 57 40 0 36 38 48 133
41 43 43 45 56 60 45 44
 

#include <stdio.h>
#include <string.h>

int not_alphabet(char a)
{
	if(a>=97&&a<=122 || a>=65&&a<=90)
		return 0;
	return 1;
}

char str[1001];
char temp;
int n,i,length,m;
int main()
{
	scanf("%d",&n);
	getchar();
	while(n--)
		{
			gets(str);
			scanf("%d",&m);
			length=strlen(str);
			for(i=0;i<length;i++)//小换大
			{
				if(str[i]>=97 && str[i]<=122)
					str[i]=str[i]-32;
			}
			for(i=0;i<length;i++)//输出
			{
				if(i>0)
					printf(" ");
				temp=str[i];
				if( not_alphabet(str[i])==1 )
					if(str[i]==' ')
						printf("0");
					else
					    printf("%d",temp+100);
				else
					printf("%d",temp-'A'+1+m);
			}
			printf("\n");
			getchar();
		}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/HurryBen/article/details/105717312
68
今日推荐