ZZULIOJ 1064加密字符

 

 

题目描述

从键盘输入一批字符,以@结束,按要求加密并输出。

输入

从键盘输入一批字符,占一行,以@结束。

输出

输出占一行
加密规则:
1)所有字母均转换为小写。
2)若是字母'a'到'y',则转化为下一个字母。
3)若是'z',则转化为'a'。
4)其它字符,保持不变。

样例输入 Copy

Kyh520@

样例输出 Copy

lzi520
#include
int main()
{
	char ch;
	while(scanf("%c",&ch),ch!='@')
	{
		if(ch>='A'&&ch<='Z')
		{
			ch=ch+32;
			if(ch>='a'&&ch<='y')
				ch=ch+1;
			else if(ch=='z')
				ch='a';
			printf("%c",ch);
		}
		else if(ch>='a'&&ch<='y')
		{
			ch=ch+1;
			printf("%c",ch);
		}
		else if(ch=='z')
		{
			ch='a';
			printf("%c",ch);
		}
		else
			printf("%c",ch);
	}
	return 0;
}

JAVA代码

import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	char x;
	int i=0;
	String s=sc.nextLine();
	while (true)
	{
		x=s.charAt(i);
		i++;
		if (x=='@') break;
		if (x>='A'&&x<='Z') x=(char)(x+32);
		if (x>='a'&&x<'z') x=(char)(x+1);
		else if (x=='z') x='a';
		System.out.print(x);
	}
	sc.close();
	}
}

 

你可能感兴趣的:(zzulioj,JAVA)