ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1002. Телефонные номера

wrong answer in most tests. 1002.cpp
Послано Dheeraj Dhall 9 ноя 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
Послано Abdujabbor 25 авг 2014 01:13
this I think:

cout<<"no solution";

cout<<"No solution";
Re: wrong answer in most tests. 1002.cpp
Послано Ashok 8 фев 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
Послано Ashok 8 фев 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
Послано TravisGRivera 22 июн 2015 02:49
actually should be "No solution." remember the period.