输入是一个字符串,字符串长度不超过 80 个字符。
输出其反码
Hello
Svool
JLU-CCST-2011
QOF-XXHG-2011
#include<iostream> using namespace std; int main() { string s; cin >> s; for(int i=0; i<s.length(); i++) { if( s[i]>='a'&&s[i]<='z' ) { s[i] = 'z' + 'a' - s[i]; } if( s[i]>='A'&&s[i]<='Z' ) { s[i] = 'Z' + 'A' - s[i]; } } cout << s << endl; }
#include<stdio.h> #include<string.h> int main() { char a[100]; int n,i; while(gets(a)) { if(a[0]=='!'&&a[1]=='\0') break; n=strlen(a); for(i=0;i<n;i++) { if(a[i]>='a'&&a[i]<='z') a[i]='z'-(a[i]-'a'); if(a[i]>='A'&&a[i]<='Z') a[i]='Z'-(a[i]-'A'); } printf("%s\n",a); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ String s = scanner.next(); if (s.equals("!")){ break; }else { StringBuilder builder = new StringBuilder(); char[] array = s.toCharArray(); for (char c : array) { if (c >= 'a' && c <= 'z') builder.append((char) ('z' - (c - 'a'))); else if (c>='A'&&c<='Z') builder.append((char) ('Z' - (c - 'A'))); else builder.append(c); } System.out.println(builder.toString()); } } } }
#include<bits/stdc++.h> using namespace std; int main(){ char ch[81]; while(cin>>ch){ if(ch[0]=='!') break; for(int i=0;i<strlen(ch);i++){ if(ch[i]>='a'&&ch[i]<='z') cout<<(char)('a'+(25-(ch[i]-'a'))); else if(ch[i]>='A'&&ch[i]<='Z') cout<<(char)('A'+(25-(ch[i]-'A'))); else cout<<ch[i]; } cout<<endl; } }
#include<iostream> #include<string> using namespace std; int main() { string str; while(getline(cin,str)) { if(str=="!") break; else { for(int i=0;i<str.length();i++) { if(str[i]>='a' && str[i]<='z') printf("%c",(int)('z'-(str[i]-'a'))); else if(str[i]>='A' && str[i]<='Z') printf("%c",(int)('Z'-(str[i]-'A'))); else printf("%c",str[i]); } printf("\n"); } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(""); while(sc.hasNext()){ String str = sc.nextLine(); if('!' == str.charAt(0)){ break; } char[] ch = str.toCharArray(); for(int i=0;i<ch.length;i++){ sb.append(rev(ch[i])); } System.out.print(sb); } } public static char rev(char c){ if(c>='a' && c<='z'){ return (char)('z'+'a'-c); }else if(c>='A' && c<='Z'){ return (char)('A'+'Z'-c); } return c; } }
#include <stdio.h> int main() { char s[80]; scanf("%s",s); for(int i=0;s[i]!='\0';i++){ switch(s[i]){ case 'a':s[i]='z';break; case 'b':s[i]='y';break; case 'c':s[i]='x';break; case 'd':s[i]='w';break; case 'e':s[i]='v';break; case 'f':s[i]='u';break; case 'g':s[i]='t';break; case 'h':s[i]='s';break; case 'i':s[i]='r';break; case 'j':s[i]='q';break; case 'k':s[i]='p';break; case 'l':s[i]='o';break; case 'm':s[i]='n';break; case 'n':s[i]='m';break; case 'o':s[i]='l';break; case 'p':s[i]='k';break; case 'q':s[i]='j';break; case 'r':s[i]='i';break; case 's':s[i]='h';break; case 't':s[i]='g';break; case 'u':s[i]='f';break; case 'v':s[i]='e';break; case 'w':s[i]='d';break; case 'x':s[i]='c';break; case 'y':s[i]='b';break; case 'z':s[i]='a';break; case 'A':s[i]='Z';break; case 'B':s[i]='Y';break; case 'C':s[i]='X';break; case 'D':s[i]='W';break; case 'E':s[i]='V';break; case 'F':s[i]='U';break; case 'G':s[i]='T';break; case 'H':s[i]='S';break; case 'I':s[i]='R';break; case 'J':s[i]='Q';break; case 'K':s[i]='P';break; case 'L':s[i]='O';break; case 'M':s[i]='N';break; case 'N':s[i]='M';break; case 'O':s[i]='L';break; case 'P':s[i]='K';break; case 'Q':s[i]='J';break; case 'R':s[i]='I';break; case 'S':s[i]='H';break; case 'T':s[i]='G';break; case 'U':s[i]='F';break; case 'V':s[i]='E';break; case 'W':s[i]='D';break; case 'X':s[i]='C';break; case 'Y':s[i]='B';break; case 'Z':s[i]='A';break; } } printf("%s",s); }
def revword(s): res = [] for i in range(len(s)): if ord('A') <= ord(s[i]) and ord(s[i]) <= ord('Z'): a = ord(s[i]) - ord('A') r = ord('Z') - a res.append(chr(r)) elif ord('a') <= ord(s[i]) and ord(s[i]) <= ord('z'): a = ord(s[i]) - ord('a') r = ord('z') - a res.append(chr(r)) # elif ord('a') == ord(s[i]): # res.append('z') # elif ord('z') == ord(s[i]): # res.append('a') else: res.append(s[i]) return ''.join(res) s = input() print(revword(s))
#include <iostream> #include <string> using namespace std; int main() { string str; while (cin >> str) { for (auto& ch : str) { if (ch >= 'A' && ch <= 'Z') { ch -= 'A'; ch = 25 - ch; ch += 'A'; } else if (ch >= 'a' && ch <= 'z') { ch -= 'a'; ch = 25 - ch; ch += 'a'; } } cout << str << endl; } return 0; }
#include <iostream> using namespace std; int main() { string a; cin >> a; for(int i = 0; a[i]; i++) { if(a[i] >= 'a' && a[i] <= 'z') a[i] = 25 - (a[i] - 'a') + 'a'; if(a[i] >= 'A' && a[i] <= 'Z') a[i] = 25 - (a[i] - 'A') + 'A'; } cout << a << endl; return 0; }
#include <cstdio> #include <iostream> #include <string> using namespace std; int main(){ string str; while(cin>>str){ for(int i = 0; i < str.size(); ++i){ if( ('a'<=str[i] && str[i]<='z') || ('A'<=str[i] && str[i]<='Z')){ int x; //偏移量 if('a'<=str[i] && str[i]<='m'){ x = str[i]-'a'; str[i] = 'z'-x; }else if('n'<=str[i] && str[i]<='z'){ x = 'z'-str[i]; str[i] = 'a'+x; }else if('A'<=str[i] && str[i]<='M'){ x = str[i]-'A'; str[i] = 'Z'-x; }else if('N'<=str[i] && str[i]<='Z'){ x = 'Z'-str[i]; str[i] = 'A'+x; } } } cout<<str<<endl; } return 0; }
#include <cctype> #include <iostream> using namespace std; string fan(string s){ for(int i=0;i<s.size();i++){//遍历字符串 if(islower(s[i])){//如果是小写字母 s[i]=(25-(int)(s[i]-'a'))+'a'; } if(isupper(s[i])){//如果是大写字母 s[i]=(25-(int)(s[i]-'A'))+'A'; } } return s; } int main() { string s; while(cin>>s){ cout<<fan(s)<<endl; } }
#include <iostream> using namespace std; int main() { char str[81]; while (cin >> str) { for (int i = 0 ; str[i] != '\0' ; i++) { if (str[i] >= 'A' && str[i] <= 'Z') { str[i] = 'Z' - (str[i] - 'A'); } if (str[i] >= 'a' && str[i] <= 'z') { str[i] = 'z' - (str[i] - 'a'); } } for (int i = 0 ; str[i] != '\0' ; i++) { cout << str[i]; } cout << endl; } }
#include<iostream> using namespace std; int isAlpha(char x) { if(x>='a'&&x<='z') return 1; if(x>='A'&&x<='Z') return 2; return 0; } int main() { string str; while(cin>>str) { if(str=="!") break; for(int i=0;i<str.size();i++) { int temp=isAlpha(str[i]); if(temp==1) str[i]='z'-(str[i]-'a'); if(temp==2) str[i]='Z'-(str[i]-'A'); } cout<<str<<endl; } }
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) { if (s.equals("!")) break; StringBuilder re = new StringBuilder(""); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 'a' && c <= 'z') { re.append(fun(c)); } else if (c >= 'A' && c <= 'Z') { re.append(Fun(c)); } else { re.append(c); } } System.out.println(re); } } private static char fun(char c) { int t = c - 'a'; return (char) ('z' - t); } private static char Fun(char c) { int t = c - 'A'; return (char) ('Z' - t); } }
#include <iostream> #include <string> using namespace std; int main() { string str; while(cin >> str && str!="!") { for(int i=0;i<str.size();i++) { if(str[i]>='A'&&str[i]<='Z') { str[i]='Z'-(str[i]-'A'); } else if(str[i]>='a'&&str[i]<='z') { str[i]='z'-(str[i]-'a'); } cout << str[i]; } cout << endl; } return 0; }