Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input.
You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output.
O S, GOMR YPFSU/
I AM FINE TODAY.
#include<iostream> #include<string> #include<cstring> using namespace std; int main(){ string str; char table1[10]={'9','`','1','2','3','4','5','6','7','8'}; char table2[26]={'a','V','X','S','W','D','F','G','U','H','J','K','N', 'B','I','O','q','E','A','R','Y','C','Q','Z','T','z'}; while(getline(cin,str)){ char ch[100]; strcpy(ch,str.c_str()); for(int i=0;i<strlen(ch);i++){ if(ch[i]>='0'&&ch[i]<='9'){ ch[i]=table1[ch[i]-'0']; continue; } if('A'<=ch[i]&&ch[i]<='Z'){ ch[i]=table2[ch[i]-'A']; continue; } if(ch[i]=='='){ ch[i]='-'; continue; } if(ch[i]=='-') ch[i]='0'; if(ch[i]=='.'){ ch[i]=','; continue; } if(ch[i]=='/') ch[i]='.'; if(ch[i]==',') ch[i]='M'; if(ch[i]==';') ch[i]='L'; if(ch[i]=='[') ch[i]='P'; if(ch[i]==']') ch[i]='['; if(ch[i]=='\'') ch[i]=';'; } cout<<ch<<endl; } }
#include<bits/stdc++.h> using namespace std; int main() { //键盘字符 string key = "1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; string s; while(getline(cin,s)) { string res; int position; for(int i=0;i<s.size();i++) { if(s[i]==' ') res += s[i]; else{ position = key.find(s[i],0); res += key[position-1]; } } cout<<res<<endl; } return 0; }
//预处理思想很棒 #include <stdio.h> #include <string.h> #include <ctype.h> char code[46]={ 'Q','W','E','R','T','Y','U','I','O','P','[',']','\\', 'A','S','D','F','G','H','J','K','L',';','\'', 'Z','X','C','V','B','N','M',',','.','/', '1','2','3','4','5','6','7','8','9','0','-','=' }; int main(){ char c; int i; while(c=getchar()){ if(c=='\n') break; if(c==' '){ printf(" "); continue; } for(i=0;i<46;i++){ if(code[i]==c){ putchar(code[i-1]); break; } } } return 0; }
#include<stdio.h>
#include<string.h>
char str[10000+10], ht[300];
const char* keyboard[] = {"1234567890-=","QWERTYUIOP[]\\", "ASDFGHJKL;'", "ZXCVBNM,./"};
void init(){
int i, len, j;
for(i = 0; i<300; i++)
ht[i] = i;
for(i = 0; i<4; i++){
len = strlen(keyboard[i]);
for(j = 1; j<len; j++){
ht[keyboard[i][j]] = keyboard[i][j-1];
}
}
}
void solve(){
int i, len = strlen(str);
for(i = 0; i<len; i++){
printf("%c", ht[str[i]]);
}
printf("\n");
}
int main(){
init();
//freopen("in.txt", "r", stdin);
while(gets(str)){
solve();
}
return 0;
}
#include <array> #include <iostream> #include <map> #include <string> using namespace std; array<string, 4>arr = { "1234567890-=", "QWERTYUIOP[]\\", "ASDFGHJKL;'", "ZXCVBNM,./" }; map<char, char>myMap; void Initial() { myMap[' '] = ' '; for (const auto& str : arr) { for (int i = 0; i < str.size() - 1; i++) { myMap[str[i + 1]] = str[i]; } } } int main() { Initial(); string str1, str2; while (getline(cin, str1)) { for (const auto& ch : str1) { str2 += myMap[ch]; } cout << str2 << endl; } return 0; }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static String s1 = "QWERTYUIOP[]"; static String s2 = "ASDFGHJKL;'"; static String s3 = "ZXCVBNM,./"; static String s4 = "1234567890-="; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = br.readLine()) != null) { StringBuilder sb = new StringBuilder(str); for (int i = 0; i < str.length(); i++) { char c1 = str.charAt(i);//原来的符号 if (s1.indexOf(c1) != -1) { Replace(c1, sb, i, s1); } else if (s2.indexOf(c1) != -1) { Replace(c1, sb, i, s2); } else if (s3.indexOf(c1) != -1) { Replace(c1, sb, i, s3); } else if (s4.indexOf(c1) != -1) { Replace(c1, sb, i, s4); } } System.out.println(sb); } } public static void Replace(char c1, StringBuilder sb, int index, String s) { int c2index = s.indexOf(c1) - 1; char c2 = s.charAt(c2index); sb.setCharAt(index, c2); } }
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <cmath> #include <map> #include <set> using namespace std; int main() { string str = "1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; string s; getline(cin, s); for (int i = 0; i < s.size(); i++) { int pos = str.find(s[i]); if (pos != string::npos) { s[i] = str[pos - 1]; } } cout << s << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ map<char,char> mp; mp['W'] = 'Q'; mp['E'] = 'W'; mp['R'] = 'E'; mp['T'] = 'R'; mp['Y'] = 'T'; mp['U'] = 'Y'; mp['I'] = 'U'; mp['O'] = 'I'; mp['P'] = 'O'; mp['['] = 'P'; mp['S'] = 'A'; mp['D'] = 'S'; mp['F'] = 'D'; mp['G'] = 'F'; mp['H'] = 'G'; mp['J'] = 'H'; mp['K'] = 'J'; mp['L'] = 'K'; mp[';'] = 'L'; mp['X'] = 'Z'; mp['C'] = 'X'; mp['V'] = 'C'; mp['B'] = 'V'; mp['N'] = 'B'; mp['M'] = 'N'; mp[','] = 'M'; mp[']'] = '['; mp['\\'] = ']'; mp['\''] = ';'; mp['.'] = ','; mp['/'] = '.'; mp['1'] = '`'; mp['2'] = '1'; mp['3'] = '2'; mp['4'] = '3'; mp['5'] = '4'; mp['6'] = '5'; mp['7'] = '6'; mp['8'] = '7'; mp['9'] = '8'; mp['0'] = '9'; mp['-'] = '0'; mp['='] = '-'; mp['Q']='Q'; mp['A']='A'; mp['Z']='Z'; string str; while(getline(cin,str)){ string s1; for(int i=0;i<str.length();i++){ if(str[i]!=' '){ s1+=mp[str[i]]; }else{ s1+=str[i]; } } cout<<s1<<endl; } return 0; }
#include <iostream> (720)#include <string> #include <unordered_map> using namespace std; int main(){ string line; getline(cin, line); string c1 = R"(234567890-=WERTYUIOP[]\SDFGHJKL;'XCVBNM,./ )"; string c2 = R"(1234567890-QWERTYUIOP[]ASDFGHJKL;ZXCVBNM,. )"; unordered_map<char, char> mp; int n = c1.length(), m = line.length(); for(int i=0; i<n; i++) mp[c1[i]] = c2[i]; for(int i=0; i<m; i++) cout<<mp[line[i]]; return 0; }
#include <iostream> #include <map> using namespace std; char key[47] = {"1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"}; map<char, int> mp; void init() { for(int i = 0; i < 46; i++) { mp[key[i]] = i; } } int main() { init(); string s; while(getline(cin, s)) { for(int i = 0; i < s.size(); i++) { if(s[i] == ' ') cout <<s[i]; else cout <<key[mp[s[i]] - 1]; } cout <<endl; } return 0; }
//一定要有空格(' ')对应的映射,' '的ascII码为32,而不映射则变为空,空的ascii码为0。 //虽然看上去空格和空都输出空格,实际不是一个东西。 #include<string> #include<iostream> #include<map> using namespace std; string a; map<char, char> pro; string wrong = " 234567890-=WERTYUIOP[]SDFGHJKL;'\\XCVBNM,./"; string correct = " 1234567890-QWERTYUIOP[ASDFGHJKL;'ZXCVBNM,."; int main() { for (int i = 0; i < correct.size(); i++) pro[wrong[i]] = correct[i]; while (getline(cin, a)) { string cor=""; for (int i = 0; i < a.size(); i++) cor.push_back(pro[a[i]]); cout << cor << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ char right[]={'`','1','2','3','4','5','6','7','8','9','0' ,'-','Q','W','E','R','T','Y','U','I','O','P','[',']','A', 'S','D','F','G','H','J','K','L',';','Z','X','C','V','B','N','M',',','.'}; char wrong[]={'1','2','3','4','5','6','7','8','9','0','-','=','W','E','R','T','Y','U','I','O','P' ,'[',']','\\','S','D','F','G','H','J','K','L',';','\'','X','C','V','B','N','M',',','.','/'}; char ch; while((ch=cin.get())!='\n'){ if(ch==' ') cout<<' '; else { char * i=find(wrong,wrong+sizeof(wrong)/sizeof(char),ch); cout<<right[i-wrong]; } } char * i=find(wrong,wrong+sizeof(wrong)/sizeof(char),'M'); // cout<<i-wrong; // cout<<right[i-wrong]; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string s = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; string input = ""; getline(cin,input); for(int i = 0;i<input.length();i++) { if(input[i]==' '||input[i]=='A'||input[i]=='Q'||input[i]=='Z') { continue; } else { int index = s.find_first_of(input[i])-1; input[i] = s[index]; } } cout<<input<<endl; }
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <vector> #include <map> #include <cmath> #include <set> #include <queue> using namespace std; string s[] = {"`1234567890-=","~!@#$%^&*()_+","QWERTYUIOP[]\\","ASDFGHJKL;'","{}",":\"","ZXCVBNM,./","<>?"}; int isIn(string s,char c) { for(int i = 0 ;i<s.length();i++) if(s[i] == c) return i; return -1; } int main() { string str; while(getline(cin,str)) { for(int i = 0 ;i<str.length();i++) { for(int j = 0;j<8;j++) { int x = isIn(s[j],str[i]); if(x != -1) { str[i] = s[j][x-1]; break; } } } cout << str << endl; } }
int main() {
string origin, ans;
getline(cin, origin);
ans = origin;
map<char, char> myMap;
myMap['W'] = 'Q';
myMap['E'] = 'W';
myMap['R'] = 'E';
myMap['T'] = 'R';
myMap['Y'] = 'T';
myMap['U'] = 'Y';
myMap['I'] = 'U';
myMap['O'] = 'I';
myMap['P'] = 'O';
myMap['['] = 'P';
myMap['S'] = 'A';
myMap['D'] = 'S';
myMap['F'] = 'D';
myMap['G'] = 'F';
myMap['H'] = 'G';
myMap['J'] = 'H';
myMap['K'] = 'J';
myMap['L'] = 'K';
myMap[';'] = 'L';
myMap['X'] = 'Z';
myMap['C'] = 'X';
myMap['V'] = 'C';
myMap['B'] = 'V';
myMap['N'] = 'B';
myMap['M'] = 'N';
myMap[','] = 'M';
myMap[']'] = '[';
myMap['\\'] = ']';
myMap['\''] = ';';
myMap['.'] = ',';
myMap['/'] = '.';
myMap['1'] = '`';
myMap['2'] = '1';
myMap['3'] = '2';
myMap['4'] = '3';
myMap['5'] = '4';
myMap['6'] = '5';
myMap['7'] = '6';
myMap['8'] = '7';
myMap['9'] = '8';
myMap['0'] = '9';
myMap['-'] = '0';
myMap['='] = '-';
for (int i = 0; i < origin.length(); i++) {
if (origin[i] == ' ')
ans[i] = origin[i];
else {
ans[i] = myMap[origin[i]];
}
}
cout << ans << endl;
system("pause");
return 0;
}