题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include<bits/stdc++.h>
using namespace std;
int main(void) { vector D; vector out; string temp; temp = "abcdefghijklmnopqrstuvwxyz"; for(int i = 0;i<8;i++) { if(i<=4) D.push_back(temp.substr(3i,3)); else if(i==5) D.push_back(temp.substr(3i,4)); else if(i==6) D.push_back(temp.substr(3i+1,3)); else if(i==7) D.push_back(temp.substr(3i+1)); }//D[0] - D[7] == 2-9 temp.clear(); while(cin>>temp) { string str; int size = temp.size(); for(int i=0;i<size;i++) { if(temp[i]>= '0' && temp[i]<= '9') { str = temp[i]; out.push_back(str); str.clear(); } if(temp[i]>= 'a' && temp[i]<= 'z') { for(int j =0;j<8;j++) if(D[j].find(temp[i]) != D[j].npos) { str = (j+2) + '0'; out.push_back(str); str.clear(); } } if(temp[i]>= 'A' && temp[i]< 'Z') { temp[i] += 33; str = temp[i]; out.push_back(str); str.clear(); } else if(temp[i] == 'Z') { temp[i] = 'a'; str = temp[i]; out.push_back(str); str.clear(); }
}
int siz = out.size();
for(int i =0;i<siz;i++)
{
cout<<out[i];
}
}
}