739 - Soundex Indexing

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

Moderator: Board moderators

sushil2006090
New poster
Posts: 7
Joined: Wed Feb 20, 2008 3:17 pm
Contact:

739 sm1 plz help me.. got loads of PE

Post by sushil2006090 »

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
//#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
//#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include<queue>
#include<map>
#include<string>
using namespace std;
int main()
{
string str;
for(int i=0;i<10;i++)
cout<<" ";
cout<<"NAME";
for(int i=0;i<21;i++)
cout<<" ";
cout<<"SOUNDEX CODE\n";
while(cin>>str)
{
string ans;
ans+=str[0];
int len=str.length();
map<char,int>m;
m['B']=1;m['P']=1;m['F']=1;m['V']=1;m['C']=2;m['S']=2;m['K']=2;m['G']=2;m['J']=2;m['Q']=2;m['X']=2;m['Z']=2;
m['D']=3;m['T']=3;m['L']=4;m['M']=5;m['N']=5;m['R']=6;
int pos=1;
for(int i=1;i<len;i++)
{
for(map<char,int>::iterator it=m.begin();it!=m.end();it++)
{
if((*it).first==str)
{


bool flag=true;


if((i-1)>=0)
{
for(map<char,int>::iterator ii=m.begin();ii!=m.end();ii++)
{
if(str[i-1]==(*ii).first && (*ii).second==(*it).second)
{ flag=false;break;}
}
}

if(flag==true)
{
ans+=((*it).second+'0'); pos++;

}

}
}
if(pos==4)
break;
}


int l=ans.length();
while(l<4)
{ans+='0';l++;}

for(int i=0;i<10;i++)
cout<<" ";
cout<<str;
int ll=str.length();
for(int i=0;i<25-ll;i++)
cout<<" ";
cout<<ans<<endl;

}
for(int i=0;i<20;i++)
cout<<" ";
cout<<"END OF OUTPUT\n";

//system("pause");
}


plz debug it for presentation error.........

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 739 - Soundex Indexing

Post by Obaida »

Check the sample input very carefully the see how many space you need to print.
I think to go to the 20th column you need to print 19 space.. :wink:

>>And plz remove your code after acc.(hope every one get it soon.)
try_try_try_try_&&&_try@try.com
This may be the address of success.

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

739- Getting PE and WA, But why??? Plz some1 help me. plz

Post by Eather »

Delete after AC
Last edited by Eather on Fri Oct 08, 2010 9:04 am, edited 1 time in total.

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

Re: 739 - Soundex Indexing

Post by Eather »

Got AC. :) I have found my prblm and got AC.. Just to print the correct position is the way to get AC without WA or PE.

Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh
Contact:

Re: 739 - Soundex Indexing

Post by Shafaet_du »

For those who are getting PE, Here's how i printed the output in my ac code:

header:
REP(i,9) printf(" "); printf("NAME");
REP(i,21) printf(" "); printf("SOUNDEX CODE\n");

body:
REP(i,9) printf(" "); cout<<S;
REP(i,35-9-S.size()-1) printf(" "); cout<<OUT<<endl;

footer:
REP(i,19) printf(" ");
printf("END OF OUTPUT\n");

dhruba07
New poster
Posts: 20
Joined: Tue May 21, 2013 9:02 pm
Location: BUET

Re: 739 - Soundex Indexing

Post by dhruba07 »

all test cases match but why Wrong Ans ! :( :(

removed after AC :)
Last edited by dhruba07 on Sat Jun 15, 2013 12:35 pm, edited 1 time in total.
Accept who you are :)

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 739 - Soundex Indexing

Post by brianfry713 »

Try increasing the size of coded by 1 and null terminating it.
Check input and AC output for thousands of problems on uDebug!

dhruba07
New poster
Posts: 20
Joined: Tue May 21, 2013 9:02 pm
Location: BUET

Re: 739 - Soundex Indexing

Post by dhruba07 »

brianfry713 wrote:Try increasing the size of coded by 1 and null terminating it.

for some reason in my gcc compiler it was showing the right output . But on the other compilers garbage values are printed . I added a null terminator in the end and got ac :D
Accept who you are :)

Diaa.Abobaraka
New poster
Posts: 3
Joined: Mon Feb 11, 2013 5:44 pm

Re: 739 - Soundex Indexing

Post by Diaa.Abobaraka »

test all available test cases but still WA ..Any help ?

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		String one = "BPFV";
		String two = "CSKGJQXZ";
		String three = "DT";
		String four = "L";
		String five = "MN";
		String six = "R";
		String breaking = "AEIOUYW";

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String name;
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 9; i++)
			sb.append(" ");
		sb.append("NAME");
		for (int i = sb.length(); i < 35; i++)
			sb.append(" ");
		sb.append("SOUNDEX CODE\n");

		char ch;
		String code;
		boolean[] bn = new boolean[6];
		while ((name = bf.readLine()) != null ) {
			Arrays.fill(bn, false);
			code = "";

			for (int i = 0; i < 9; i++)
				sb.append(" ");
			sb.append(name);
			for (int i = 9 + name.length(); i < 35; i++)
				sb.append(" ");

			for (int i = 0; i < name.length(); i++) {
				ch = name.charAt(i);

				if (one.contains(ch + "")) {
					if (i == 0) {

						code += name.charAt(0) + "";

					} else {
						if (!bn[0]) {
							code += "1";
						}
					}
					Arrays.fill(bn, false);
					bn[0] = true;

				} else if (two.contains(ch + "")) {

					if (i == 0) {
						code += name.charAt(0) + "";

					} else {
						if (!bn[1]) {
							code += "2";
						}
					}
					Arrays.fill(bn, false);
					bn[1] = true;
				} else if (three.contains(ch + "")) {
					if (i == 0) {
						code += name.charAt(0) + "";

					} else {
						if (!bn[2]) {
							code += "3";
						}
					}
					Arrays.fill(bn, false);
					bn[2] = true;
				} else if (four.contains(ch + "")) {
					if (i == 0) {
						code += name.charAt(0) + "";

					} else {
						if (!bn[3]) {
							code += "4";
						}
					}
					Arrays.fill(bn, false);
					bn[3] = true;
				} else if (five.contains(ch + "")) {
					if (i == 0) {
						code += name.charAt(0) + "";

					} else {
						if (!bn[4]) {
							code += "5";
						}
					}
					Arrays.fill(bn, false);
					bn[4] = true;
				} else if (six.contains(ch + "")) {
					if (i == 0) {
						code += name.charAt(0) + "";

					} else {
						if (!bn[5]) {
							code += "6";
						}
					}
					Arrays.fill(bn, false);
					bn[5] = true;
				} else if (breaking.contains(ch + "")) {
					if (i == 0) {

						code += name.charAt(0) + "";

					} else {
						Arrays.fill(bn, false);
					}

				}
				if (code.length() == 4) {
					break;
				}

			}
			while (code.length() < 4) {
				code += 0;
			}
			sb.append(code + "\n");
		}
		for (int i = 0; i < 19; i++)
			sb.append(" ");
		sb.append("END OF OUTPUT\n");

		System.out.println(sb);

	}

}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 739 - Soundex Indexing

Post by brianfry713 »

You're printing SOUNDEX CODE one column to the right of where it should be.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 7 (700-799)”