![:D](./images/smilies/icon_biggrin.gif)
10352 - Count the eWords
Moderator: Board moderators
Re: [b]May Be This Is The Output:[/b]
What is the *correct* output for abc ab abcd abe abd #?Helal Md. Morshed Alam wrote:ab 1
abd 3
abcd 1
I know that this *may* be the correct one...
![:(](./images/smilies/icon_frown.gif)
(so simple task, and 7WA!)
![:cry:](./images/smilies/icon_cry.gif)
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
What's wrong
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]
[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
Lucindo
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
10352
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
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
The problem description is WRONG.
intput:
output: (from AC solution) 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:](./images/smilies/icon_redface.gif)
intput:
Code: Select all
xxab xxbb xxba xxaa
#
cd cde
#
Code: Select all
Set #1:
xxaa 2
xxbb 2
Set #2:
cd 1
cde 1
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:](./images/smilies/icon_redface.gif)
Why Wrong Ans don't know, any critical input????????
#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;
}
#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
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
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:](./images/smilies/icon_evil.gif)
is the total output words more than 4100?
Please help me
Hi,
Here's my output:
I do not believe symbols appear because I didn't handle them in my program. And my list has a maximum size of 5000.
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