739 - Soundex Indexing
Moderator: Board moderators
-
- New poster
- Posts: 7
- Joined: Wed Feb 20, 2008 3:17 pm
- Contact:
739 sm1 plz help me.. got loads of PE
#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.........
#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
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..
>>And plz remove your code after acc.(hope every one get it soon.)
I think to go to the 20th column you need to print 19 space..

>>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.
This may be the address of success.
739- Getting PE and WA, But why??? Plz some1 help me. plz
Delete after AC
Last edited by Eather on Fri Oct 08, 2010 9:04 am, edited 1 time in total.
Re: 739 - Soundex Indexing
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.

-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 739 - Soundex Indexing
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");
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");
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
Re: 739 - Soundex Indexing
all test cases match but why Wrong Ans !
removed after AC


removed after AC

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

-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 739 - Soundex Indexing
Try increasing the size of coded by 1 and null terminating it.
Check input and AC output for thousands of problems on uDebug!
Re: 739 - Soundex Indexing
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

Accept who you are 

-
- New poster
- Posts: 3
- Joined: Mon Feb 11, 2013 5:44 pm
Re: 739 - Soundex Indexing
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);
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 739 - Soundex Indexing
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!