Donghua OJ 66 encryption

Problem Description :

Preparation of an encrypted program, used to encrypt a string. Encryption rules are as follows:

  1. All numbers in a string 0,1 ... 9 are made lowercase letters a, b ... j.

  2. The string of all lowercase letters a, b ... j are converted to digital 0,1 ... 9.

  3. Other characters remain unchanged.

Enter a description:

Your program needs from the standard input device (usually keyboard) reads multiple sets of test data. Each set of input data per line, which contains only a character string, i.e. a string to be encrypted. The string contains no more than 100 characters, contain only ASCII characters visible, with no spaces, tabs, or new. Beginning of the line end of the line and no extra spaces; not all data before and after the extra blank line; no extra blank line between the two sets of data.

Output Description:

For each test case, you need to program (typically a text terminal to start the program, the program start command, for example, you used in Windows Terminal line) are sequentially output to the standard output corresponding to a set of answers. Each answer per line, which contains only a character string, i.e., the encryption result in the problem statement. Beginning of the line and the end of the line do not print extra spaces; do not print extra blank line before and after all the data; do not print extra blank line between the two sets of data.

Input example: s1drasdfnmsdafn.

Sample output: sb3r0s35nms305n.

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

int main(){
	char str[101];

	while(gets(str)){
	for(int i=0;str[i]!='\0';i++){
		if(str[i]>='0'&&str[i]<='9')
			str[i]=str[i]-'0'+'a';
		else if(str[i]>='a'&&str[i]<='j')
			str[i]=str[i]-'a'+'0';
	}

	for(int j=0;str[j]!='\0';j++)
		printf("%c",str[j]);
	
	memset(str,0,sizeof(str));
	printf("\n");
	}
	return 0;
}

 

Released three original articles · won praise 0 · Views 41

Guess you like

Origin blog.csdn.net/Sanbai__/article/details/104343616