10260 - Soundex

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

ultima_key
New poster
Posts: 10
Joined: Tue Mar 25, 2014 12:50 pm

Re: 10260 - Soundex

Post by ultima_key »

I am getting wrong answer but I think I handled all the test cases correctly. Here is my code:

Code: Select all

//
//  soundex.cpp
//  
//
//  Created by iOS Development on 7/10/15.
//
//

#include <iostream>
#include <map>
#define c cin
#define o cout
#define el endl
using namespace std;

map<char,char> l;
void sets(){
    for(int i=65;i<=90;i++){
        char d=i;
        if(d=='B' || d=='F' || d=='P' || d=='V') l[d]='1';
        else if(d=='C' || d=='G' || d=='J' || d=='K' || d=='Q' || d=='S' || d=='X' || d=='Z') l[d]='2';
        else if(d=='D' || d=='T') l[d]='3';
        else if(d=='L') l[d]='4';
        else if(d=='M' || d=='N') l[d]='5';
        else if(d=='R') l[d]='6';
    }
}

int main(){
    sets();
    string in;
    while(c>>in){
        int len=in.length();
        map<char,bool> chck; string tmp="";
        for(int i=0;i<len;i++){
            if(l[in[i]]!=l[in[i-1]]){
                tmp+=l[in[i]];
                chck[l[in[i]]]=true;
            }
        }
        if(tmp.length()!=0) o<<tmp<<el;
        else o<<el;
    }
}
Post Reply

Return to “Volume 102 (10200-10299)”