Page 2 of 3
Posted: Thu Sep 19, 2002 4:36 am
by Eric3k
Cool! I used a map and now it worked fine. Ran under 6 seconds. Thanks a lot for your help.

Re: [b]May Be This Is The Output:[/b]
Posted: Fri Sep 27, 2002 12:16 pm
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!)

Posted: Fri Sep 27, 2002 12:24 pm
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.
What's wrong
Posted: Sat Jan 11, 2003 11:24 pm
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]
Posted: Sat Jan 11, 2003 11:40 pm
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 #" ...
Thank you Adrian
Posted: Sun Jan 12, 2003 2:25 pm
by lucindo
Thank's Adrian for the C++ tip. I got AC now.
10352
Posted: Sun Apr 13, 2003 11:47 pm
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
Posted: Mon Apr 14, 2003 12:42 am
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
10352 WA
Posted: Tue Mar 02, 2004 11:50 am
by eloha
Can anyone tell me the output for:
cd cde #
Please give me more test data. Thanks.
Posted: Wed Nov 23, 2005 7:35 pm
by minskcity
The problem description is WRONG.
intput:
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

Posted: Sat Jul 01, 2006 7:29 pm
by daveon
[quote="AlexandreN
Why Wrong Ans don't know, any critical input????????
Posted: Tue Aug 08, 2006 1:35 pm
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;
}
10352
Posted: Mon Aug 21, 2006 1:52 pm
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
is the total output words more than 4100?
Please help me
Posted: Tue Aug 22, 2006 1:59 am
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.
Posted: Tue Aug 22, 2006 6:05 am
by Jatno
Thanx daveon.
At last i get accepted
i had the symbol problem
