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

Don't know the wrong
Posted by Mukul Barai 3 Jan 2017 20:21
Please somebody help me. I can not find the reason not to be accepted my code.

#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool found;
string convert(string str)
{
    string char_list = "22233344115566070778889990";
    string to_digit;
    for(int i=0; i<str.length(); i++)
    {
        to_digit += char_list[str[i]-97];
    }
    return to_digit;
}
void dfs(vector<int> index[], vector<int> ends[], string diction[], vector<int> track, int i, int n)
{
    if(found == true)
    {
        return;
    }
    if(i == n){
        for(int j=0; j<track.size(); j++)
        {
            cout<<diction[track[j]]<<" ";
        }
        found = true;
        return;
    }
    for(int k=0; k<ends[i].size(); k++){
        track.push_back(index[i][k]);
        dfs(index, ends, diction, track, ends[i][k], n);
        track.pop_back();
    }
}
int main()
{
    for(; ;){
        found = false;
        string number;
        cin>>number;
        if(number == "-1"){
            break;
        }
        int dic_size;
        cin>>dic_size;
        string diction[dic_size];
        for(int i=0; i<dic_size; i++){
            cin>>diction[i];
        }
        int n = number.size();
        vector<int> ends[n];
        vector<int> index[n];
        for(int j=0; j<dic_size; j++)
        {
            string str = convert(diction[j]);
            int len = diction[j].size();
            for(int i=0; i<n; i++)
            {
                if(number.substr(i,len) == str){
                    ends[i].push_back(i+len);
                    index[i].push_back(j);
                }
            }
        }
        vector<int> track;
        dfs(index, ends, diction, track, 0, n);
        if(found == false){
            cout<<"No solution.";
        }
    }
    return 0;
}

Edited by author 03.01.2017 20:24
Re: Don't know the wrong
Posted by ToadMonster 3 Jan 2017 21:31
Have you tried to compile it?

cin>>dic_size;
string diction[dic_size];

vector<int> ends[n];
ends[i].push_back(i+len);

It would be great if you post link to ideone.com (for example) run.
Run should contain expected task example output.

Edited by author 03.01.2017 21:35