|
|
back to boardWrong answer at test #1 Hello. I write program and test it on input example. It works. But when i send it i receive wrong answer at test #1. Please tell me what test fail and tell what need more in program for complete all tests. #include <iostream> #include <vector> #include <string> #include <stdlib.h> using namespace std; int table[256]; string convert(string str) { char buf[1]; string res; res.resize(str.length()); for (int i = 0; i<str.length(); i++) { sprintf(buf, "%d", table[str[i]]); res[i] = buf[0]; } return res; } void fill() { table['i'] = table['j'] = 1; table['a'] = table['b'] = table['c'] = 2; table['d'] = table['e'] = table['f'] = 3; table['g'] = table['h'] = 4; table['k'] = table['l'] = 5; table['m'] = table['n'] = 6; table['p'] = table['r'] = table['s'] = 7; table['t'] = table['u'] = table['v'] = 8; table['w'] = table['x'] = table['y'] = 9; table['o'] = table['q'] = table['z'] = 0; } int main() { fill(); string number; int numword; while(1) { cin >> number; int z = number.find('-'); if (z!=-1) break; cin >> numword; vector<string> dict(numword); for (int i = 0; i<numword; i++) { cin >> dict[i]; } int pos = 0; bool flag = false; for (int i = 0; i<numword; i++) { if (convert(dict[i]).compare(number.substr(pos, dict[i].length()))==0&&pos+dict[i].length()<=number.length()) { cout << dict[i]; if (pos+dict[i].length()<number.length()) { cout << " "; } flag = true; pos += dict[i].length(); } } if (flag==false) { cout << "No solution.\n"; } else { cout << "\n"; } } return 0; } |
|
|