10352 - Count the eWords

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

Moderator: Board moderators

Eric3k
New poster
Posts: 29
Joined: Mon Apr 29, 2002 5:22 pm
Contact:

Post by Eric3k »

Cool! I used a map and now it worked fine. Ran under 6 seconds. Thanks a lot for your help. :D

ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Re: [b]May Be This Is The Output:[/b]

Post by ftomi »

Helal Md. Morshed Alam wrote:ab 1
abd 3
abcd 1
What is the *correct* output for abc ab abcd abe abd #?
I know that this *may* be the correct one... :(
(so simple task, and 7WA!) :cry:

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

This is the "correct" output, although I think it is not correct. If the third letter is ignored, it makes no difference if there are 3 or 2 letters. But the problem setter seems to think otherwise.

lucindo
New poster
Posts: 11
Joined: Thu Sep 05, 2002 2:35 am
Contact:

What's wrong

Post by lucindo »

My code works fine for all examples in this topic but I still get WA. Can any one please tell me what's wrong??

[cpp]
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main () {
int se = 0;

while (!cin.eof()) {
string s, os;
map<string, int> pal;
map<string, string> lap;

while (cin >> s && s != "#") {
if (s.size() > 5) s = s.substr(0, 5);
os = s;
if (s.size() > 2) s[2] = ' ';
pal[s]++;
lap[s] = os;
}
cout << "Set #" << ++se << ':' << endl;
for (map<string, int>::iterator i = pal.begin(); i != pal.end(); *i++)
cout << lap[i->first] << " " << i->second << endl;
cout << endl;
}

return 0;
}
[/cpp]
[]'s

Lucindo

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

You miss the end of file. cin.eof() returns true if you tried to read something and you reach EOF. Therefore you must place it directly before cout << "Set #" ...

lucindo
New poster
Posts: 11
Joined: Thu Sep 05, 2002 2:35 am
Contact:

Thank you Adrian

Post by lucindo »

Thank's Adrian for the C++ tip. I got AC now.
[]'s

Lucindo

SoLtRiX
New poster
Posts: 10
Joined: Tue Dec 03, 2002 1:17 am
Location: Portugal
Contact:

10352

Post by SoLtRiX »

after reading all the posts, i still don't understand why i'm getting WA. i've tested the acm input and i've got the same output.
can anyone tell me whats wrong with my code?
[cpp]
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>


struct Estrut{
char inic[6];
int count;
char fim[6];
Estrut (){count=1;}
};

map <string,Estrut> mapa;
map <string,Estrut>::iterator it;

map <int,int> tabela;

int main()
{
int flag=1,number=0;
char ch[40];
while(cin>>ch)
{
if (!strcmp(ch,"#"))
{
if (number)
{
cout <<endl;
}
cout <<"Set #"<<++number<<":"<<endl;
for (it=mapa.begin();it!=mapa.end();it++)
{
cout << (*it).second.fim << " " <<(*it).second.count<<endl;
}
mapa.clear();
}
else
{
char buf1[6],buf2[6];Estrut aux;
int i;
for (i=0;i<5&&i<=strlen(ch);i++)
{
buf2=ch;
}
buf2=0;
int j;
for (j=0;j<5 && j<strlen(ch);j++)
{
if (j<2) buf1[j]=ch[j];
if (j>2) buf1[j-1]=ch[j];
}
if (j<=2) j++;
buf1[j-1]=0;
it = mapa.find(buf1);
if (it==mapa.end())
{
Estrut aux;
aux.inic=buf2;
aux.count=1;
aux.fim=buf2;
mapa.insert(pair<string,Estrut>(buf1,aux));
}
else
{
(it->second.fim)=buf2;
(it->second.count)=(it->second.count)+1;
}
}
}
}

[/cpp]
thanks for any help

SoLtRiX
New poster
Posts: 10
Joined: Tue Dec 03, 2002 1:17 am
Location: Portugal
Contact:

Post by SoLtRiX »

forget my post. i just read the old posts again and i tryed all the examples and i found some bugs that i've fixed and got AC.

thanks anyway for the ones that have posted here because i got AC only reading those posts

eloha
New poster
Posts: 38
Joined: Thu Oct 31, 2002 8:24 am
Location: Taiwan

10352 WA

Post by eloha »

Can anyone tell me the output for:

cd cde #

Please give me more test data. Thanks.

minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post by minskcity »

The problem description is WRONG.

intput:

Code: Select all

xxab xxbb xxba xxaa
#
cd cde
#
output: (from AC solution)

Code: Select all

Set #1:
xxaa 2
xxbb 2

Set #2:
cd 1
cde 1
Which is DEAD WRONG ACCORDING TO THE PROBLEM DESCRIPTION!!!!!!!!
It says that the output should be sorted by the first ignored letter, which is 'a' for xx-b and 'b' for xx-a....
xx-b should come before xx-a if you follow the problem statement, but then you would get WA :oops:

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

[quote="AlexandreN

Jatno
New poster
Posts: 6
Joined: Tue Dec 24, 2002 7:43 am
Location: Dhaka, Bangladesh
Contact:

Why Wrong Ans don't know, any critical input????????

Post by Jatno »

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#define MAX 4202

typedef struct {
char w[10];
int n;
} node;

node array[MAX];

int tot;
int low;
int high;
int val;
int mid;
int testcase;

char temp1[10],temp2[10], temp[5000];

int cmp(char *s1, char *s2) {
strcpy(temp1,s1);
strcpy(temp2,s2);
if(strlen(temp1) != 2) temp1[2] ='X';
if(strlen(temp2) != 2) temp2[2] ='X';
return (strcmp(temp1,temp2));
}


void merge(char *num) {
low = 0;
high = tot-1;
while(low <= high) {
mid = (low+high)/2;
val = cmp(num,array[mid].w);
if(val == 0) {
strcpy(array[mid].w,num);
array[mid].n++;
return;
}
else if(val < 0) //(ugly[mid] > num)
high = mid-1;
else //if(val > 0) //(ugly[mid] < num)
low = mid+1;
}

int place = (low>high) ? (low) : (high);
for(int i = tot; i > place; i--) {
strcpy(array.w,array[i-1].w);
array.n = array[i-1].n;
}
strcpy(array[place].w,num);
array[place].n = 1;
tot++;
}

void solve() {
int i;
printf("Set #%d:\n",++testcase);
for(i=0;i<tot;i++)
printf("%s %d\n",array.w, array.n);
printf("\n");
tot = 0;
}


void process(char *s) {
char *p;
p = strtok(s, " ,.!@$%^&*()_+\\/~`[]{};':\'<>?-");
while(p) {
strcpy(temp,p);
temp[5] = '\0';
if(strcmp(temp,"#") == 0) {solve(); return;}
merge(temp);
p = strtok(NULL, " ,.!@$%^&*()_+\\/~`[]{};':\'<>?-");
}
}

int main() {
char s[5000];
testcase = 0;
// freopen("in.txt","rt",stdin);
tot = 0;
while(gets(s)) {
process(s);
}
// fclose(stdin);
return 0;
}

Jatno
New poster
Posts: 6
Joined: Tue Dec 24, 2002 7:43 am
Location: Dhaka, Bangladesh
Contact:

10352

Post by Jatno »

Input:

a1e2 s@#$%^&*()-+ #
aaa aaac aadc aab aac a aa aa aax aaa aaP #
a<>?,./!@#$%^&*()_+=-0987654321`~'"?></., #
aaaaapqrs aaaaauv aacaauv aaqaapqrs #

Can anyone please send me the correct output for that sample input?

Is there any symbol can appear in sample input :evil:

is the total output words more than 4100?

Please help me

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Hi,

Here's my output:

Code: Select all

Set #1:
a1e2 1
s@#$% 1

Set #2:
a 1
aa 2
aaP 6
aadc 2

Set #3:
a<>?, 1

Set #4:
aaqaa 4
I do not believe symbols appear because I didn't handle them in my program. And my list has a maximum size of 5000.

Jatno
New poster
Posts: 6
Joined: Tue Dec 24, 2002 7:43 am
Location: Dhaka, Bangladesh
Contact:

Post by Jatno »

Thanx daveon.

At last i get accepted :lol:

i had the symbol problem :oops:

Post Reply

Return to “Volume 103 (10300-10399)”