读取这一行字符串,每个字符串长度小于80个字符
对于每组数据,输出每行字符串的加密字符串。
Hello! How are you!
Ifmmp! Ipx bsf zpv!
zzz
aaa
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String str = scanner.nextLine(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { if (str.charAt(i)>='a'&& str.charAt(i)<='y') { sb.append((char) (str.charAt(i) + 1)); }else if (str.charAt(i)>='A' && str.charAt(i)<='Y') { sb.append((char) (str.charAt(i) + 1)); }else if (str.charAt(i) == 'z') { sb.append('a'); }else if (str.charAt(i) == 'Z') { sb.append('Z'); }else { sb.append(str.charAt(i)); } } System.out.println(sb.toString()); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = br.readLine()) != null) { // int n = Integer.parseInt(str); // for (int i = 0; i < n; i++) { // String s = br.readLine(); StringBuilder sb = new StringBuilder(s); for (int j = 0; j < s.length(); j++) { char c = s.charAt(j); if ((c >= 'a' && c < 'z') || (c >= 'A' && c < 'Z')) sb.setCharAt(j, (char) (s.charAt(j) + 1)); if (c == 'z') sb.setCharAt(j, 'a'); if (c == 'Z') sb.setCharAt(j, 'A'); } System.out.println(sb); // } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); char[] array = s.toCharArray(); StringBuilder builder = new StringBuilder(); for (char c : array) { if (c>='a'&&c<'z') builder.append((char)(c+1)); else if (c>='A'&&c<'Z') builder.append((char)(c+1)); else if (c=='Z') builder.append('A'); else if (c=='z') builder.append('a'); else builder.append(c); } System.out.println(builder.toString()); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner reader = new Scanner(System.in); while (reader.hasNextLine()) { String line = reader.nextLine(); StringBuilder res = new StringBuilder(); for (int i = 0; i < line.length(); ++i) { char word = line.charAt(i); if ((word >= 'A' && word <= 'Z') || (word >= 'a' && word <= 'z')) { if (word == 'Z') word = 'A'; else if (word == 'z') word = 'a'; else word = (char)((int)word+1); } res.append(word); } System.out.println(res.toString()); } } }
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); String str=scan.nextLine(); Pattern p=Pattern.compile("[a-yA-Y]|[zZ]"); Matcher m=p.matcher(str); StringBuffer sb=new StringBuffer(); while(m.find()){ if(m.group().matches("[zZ]")){ m.appendReplacement(sb,(char)(m.group().charAt(0)-25)+""); }else{ m.appendReplacement(sb,(char)(m.group().charAt(0)+1)+""); } } m.appendTail(sb); System.out.println(sb); } }
public class Main { public String doSome(String string){ String s=""; for(int i=0;i<string.length();i++){ if((string.charAt(i)>=65&&string.charAt(i)<=90)||(string.charAt(i)>=97&&string.charAt(i)<=122)){ s=s+(char)(string.charAt(i)+1); continue; } if(string.charAt(i)==32){ s=s+(string.charAt(i)); continue; } s=s+string.charAt(i); } return s; } public static void main(String[] args) { Scanner s=new Scanner(System.in); int count=0; int size=Integer.valueOf(s.nextLine()); String input; Main m=new Main(); while(count<size){ input=s.nextLine(); System.out.println(m.doSome(input)); count++; } } }
import java.util.Scanner; /** * Created by fhqplzj on 17-2-1 at 下午1:35. */ public class Main { private static String helper(String s) { StringBuilder stringBuilder = new StringBuilder(); for (char c : s.toCharArray()) { if (Character.isAlphabetic(c)) { if (c == 'z') { stringBuilder.append('a'); } else if (c == 'Z') { stringBuilder.append('A'); } else { stringBuilder.append((char) (c + 1)); } } else { stringBuilder.append(c); } } return stringBuilder.toString(); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int n = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < n; i++) { String s = scanner.nextLine(); System.out.println(helper(s)); } } } }