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 in most tests. 1002.cpp
Posted by Dheeraj Dhall 9 Nov 2013 19:15
#include<iostream>
#include<string>
using namespace std;
string Convert(string c)
{    unsigned int i;
    string number="";
     for( i=0;i<c.size();i++)
     {
        if(c[i]=='i'||c[i]=='j')
            number=number+"1";
        else
            if
                (c[i]=='a'||c[i]=='b'||c[i]=='c')
                number=number+"2";
        else
            if(c[i]=='d'||c[i]=='e'||c[i]=='f')
                number=number+"3";
        else
            if(c[i]=='g'||c[i]=='h')
            number=number+"4";
        else
            if(c[i]=='k'||c[i]=='l')
                number=number+"5";
        else
            if(c[i]=='m'||c[i]=='n')
                number=number+"6";
        else
            if(c[i]=='p'||c[i]=='r'||c[i]=='s')
            number=number+"7";
        else
            if(c[i]=='t'||c[i]=='u'||c[i]=='v')
                number=number+"8";
        else
            if(c[i]=='w'||c[i]=='x'||c[i]=='y')
                number=number+"9";
        else
            if(c[i]=='o'||c[i]=='q'||c[i]=='z')
            number=number+"0";

}
     return number;
}
int main()
{
    string input_number = "0";
    int no_words;
    int counter = 0;

    while(input_number != "-1")
    {
     string input_number;
     cin >> input_number;
     if(input_number == "-1")
     break;



    cin>>no_words;
    string *words;
    words = new string[no_words];
    for (int i=0;i<no_words;i++)
    {
        cin>>words[i];
    }
    string *converted_words;
    converted_words= new string    [no_words];
    for (int i=0;i<no_words;i++)
        converted_words[i]=Convert(words[i]);
    for (int i=0;i<no_words;i++)
        {
        if(converted_words[i] == input_number)
        {

        cout<< words[i] << " ";
        counter ++;
        break;

        }
        }
        if(counter == 0)
        {

        cout<<"no solution";
        break;
        }





    }
return 0;

}


could someone please point out the foolishness.
Re: wrong answer in most tests. 1002.cpp
Posted by Abdujabbor 25 Aug 2014 01:13
this I think:

cout<<"no solution";

cout<<"No solution";
Re: wrong answer in most tests. 1002.cpp
Posted by Ashok 8 Feb 2015 19:28
May be you should decrease the counter.
counter--;
as you are trying to compare
counter==0;
Re: wrong answer in most tests. 1002.cpp
Posted by Ashok 8 Feb 2015 19:54
Another issue: Major one,
Your code is literally comparing the converted numbers directly to the input number. If no number is matched you have to check all the possible permutations of the converted number array.
The question is asking minimum number of words required to match the number. (GOT IT?)
Re: wrong answer in most tests. 1002.cpp
Posted by TravisGRivera 22 Jun 2015 02:49
actually should be "No solution." remember the period.