Enter the number of characters from the keyboard to @ end, as required encryption and output.

Subject description:

Input
from the keyboard input number of characters per line, ending with @.

Output
Output per line
encryption rules:
1), all letters are converted to lowercase.
2), if the letter 'a' to 'y', then into the next letter.
3), if the 'z', it is converted to 'a'.
4) Other characters remain unchanged.
Sample input
Kyh520 @
sample output
lzi520
Note: 3) and 20 are juxtaposed, not to say the change determination is performed first letter, is not 'z'. ,

Code a

# include<stdio.h>
int main()
{
	char ch;
	int count1,count2;
	while((ch=getchar())!='@') //此处逻辑运算符的优先级高于赋值运算符,加括号提高优先级
	{
		if(ch>='A'&&ch<='Z')
		{
			ch=ch+'a'-'A';
		 } 
		 if(ch>='a'&&ch<='z')
		 {
		 	if(ch=='z')
		 	{
		 		ch='a';
			  } 
			  else
			  {
			  	ch=ch+1;
			  }
		 }
		 printf("%c",ch);
	}
	return 0;
}

Note: The logical operators compared with other operators, higher priority than the priority of the assignment operator, but a lower priority than comparison operators.
Wherein the non- higher and higher or .

Code two

# include<stdio.h>
int main()
{
	char ch[1000];
	int count1,count2;
	for(count1=0; ;count1++)
	{
		scanf("%c",&ch[count1]);
		if(ch[count1]=='@')
		{
			break;
			}	
	}
	for(count2=0;count2<count1;count2++)
	{
		if(ch[count2]>='A'&&ch[count2]<='Z')
		{
			ch[count2]=ch[count2]+'a'-'A';
		}
		if(ch[count2]>='a'&&ch[count2]<='z')
		{
					if(ch[count2]=='z')
					{
						ch[count2]='a';
					}
					else
					{
					ch[count2]+=1;	
					}
					printf("%c",ch[count2]);
		}
		
	}
	return 0;
}
Published 43 original articles · won praise 1 · views 777

Guess you like

Origin blog.csdn.net/Du798566/article/details/104196787