结果显示通过
只是提供一下思路,不足之处请多指教!
#include <iostream> using namespace std; int main() { string word; while(cin>>word) { int cnt = 0; cin>>cnt; int hash[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; while(cnt--) { int a = 0; int b = 0; cin>>a>>b; for(int i = 0; i < 10; i++) { if(hash[i] == a) { hash[i] = b; } } } for(int i = 0; i < word.size(); i++) { int num = word[i] - '0'; word[i] = hash[num]+'0'; } cout<<word<<endl; } return 0; }
全部评论
(3) 回帖