ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1002. Phone Numbers

Wrong answer at test #1
Posted by Alexandr 18 Apr 2010 14:47
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;
}