Page 3 of 3

739 sm1 plz help me.. got loads of PE

Posted: Sat Aug 09, 2008 10:01 am
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.........

Re: 739 - Soundex Indexing

Posted: Tue Jul 21, 2009 8:19 pm
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.)

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

Posted: Fri Oct 08, 2010 8:32 am
by Eather
Delete after AC

Re: 739 - Soundex Indexing

Posted: Fri Oct 08, 2010 9:02 am
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.

Re: 739 - Soundex Indexing

Posted: Mon May 09, 2011 12:05 am
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");

Re: 739 - Soundex Indexing

Posted: Fri May 31, 2013 1:14 am
by dhruba07
all test cases match but why Wrong Ans ! :( :(

removed after AC :)

Re: 739 - Soundex Indexing

Posted: Tue Jun 11, 2013 2:56 am
by brianfry713
Try increasing the size of coded by 1 and null terminating it.

Re: 739 - Soundex Indexing

Posted: Sat Jun 15, 2013 12:34 pm
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

Re: 739 - Soundex Indexing

Posted: Tue Feb 11, 2014 9:50 am
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);

	}

}

Re: 739 - Soundex Indexing

Posted: Wed Feb 12, 2014 12:30 am
by brianfry713
You're printing SOUNDEX CODE one column to the right of where it should be.