## 10374 - Election

Moderator: Board moderators

naseef_07cuet
Learning poster
Posts: 62
Joined: Sat Nov 21, 2009 10:17 pm

### Re: 10374 - Election

Code: Select all

``````//Code Removed After AC!
``````
Last edited by naseef_07cuet on Sat Mar 20, 2010 10:21 pm, edited 1 time in total.
If you have determination, you can do anything you want....

New poster
Posts: 18
Joined: Sun Jan 24, 2010 11:17 am

### WA: 10374 - Election

I Got WA again & again.Can anyone help me.What's problem in my code.

Code: Select all

``````#include<iostream>
#include<string.h>
using namespace std;
int main()
{
long i,j,k,l,m,n,x,max;
char s[105][105],party[105][105],s1[10001];

scanf("%ld",&n);
x=0;
while(n--)
{
long a[1001]={0};
x++;
scanf("%ld",&m);
if(x!=1)
printf("\n");
getchar();
for(i=0;i<m;i++)
{
gets(s[i]);
gets(party[i]);
}
scanf("%ld",&l);
getchar();
for(i=0;i<l;i++)
{
gets(s1);
for(j=0;j<m;j++)
{
if(!strcmp(s1,s[j]))
{
a[j]++;
break;
}
}
}
max=0;k=0;l=0;
for(i=0;i<m;i++)
{
if(a[i]>max)
{
max=a[i];
l=i;
}
}
for(i=0;i<m;i++)
if(max==a[i])
k++;
if(max==0)
printf("\n");
else if(k>1)
printf("tie");
else
puts(party[l]);

}

return 0;
}
``````

Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Contact:

### Re: 10374 - Election

Probably there is something weird about the judge input. I took all inputs with gets,removed trailing and leading spaces,and finally got ac. ""No lines contain leading or trailing blanks. "" is not correct.

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

### Re: 10374 - Election

F*** this stupid problem. Not only the input contains leading and trailing spaces, there can be "futile" blank lines throughout the judge data which must be ignored in order to get Accepted. The judge data is SHIT...I request the admins to fix this. This kind of problem teaches you nothing but only piss you off/
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

shakil ahmed
New poster
Posts: 3
Joined: Wed Oct 12, 2011 5:20 am

### Re: 10374 - Election

WHY runtime error?????plz help.i am very new in this site.thanx................

#include <stdio.h>
#include <string.h>
struct x
{
char name [1000];
char party[1000];
char k;
} a[300];
char str[1000];
int main()
{
int n,q;
scanf("%d\n",&n);
for(q=1;q<=n;q++)
{
int m,i,j,t;
scanf("%d\n",&m);
for(i=1; i<=m; i++)
{
gets(a.name);
scanf("%s\n",a.party);
}
scanf("%d\n",&t);
for(i=1; i<=t; i++)
{
gets(str);
for(j=1; j<=t; j++)
if(strcmp(str,a[j].name)==0)
a[j].k++;
}
int max=0;
for(i=1; i<=m; i++)
if(a.k>max)
max=a.k;
for(i=1; i<=m; i++)
if(max==a.k)
{
printf("%s\n",a.party);
break;
}
for(i=1; i<=m; i++)
a.k=0;
if(n!=0)
printf("\n");
}
return 0;
}

Achilies_Saiful_Buet
New poster
Posts: 16
Joined: Wed Mar 28, 2012 7:24 pm

### Re: 10374 - Election

Having WA!! WA!! today...what's wrong with this now....plz help!! with test cases
Last edited by Achilies_Saiful_Buet on Wed May 02, 2012 12:43 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10374 - Election

The outputs of two consecutive cases will be separated by a blank line.
Check input and AC output for thousands of problems on uDebug!

Achilies_Saiful_Buet
New poster
Posts: 16
Joined: Wed Mar 28, 2012 7:24 pm

### Re: 10374 - Election

hmm i fixed it but again WA!!!!!!!!!!!!!!!!!

Code: Select all

``````#include<iostream>
#include<string>
#include<map>
#include<cstdio>

using namespace std;

string s1[32],s2[32];
int main()
{
//	freopen("10374in.txt","r",stdin);
int n,m,i,j,res,k,t;
char ch;
string str;
map<string,int>mp;
bool flag,check=false;
cin>>t;

for(i=0;i<t;i++)
{
if(check)cout<<endl;
if(!check)check=true;
mp.clear();
cin>>n;
getchar();
for(j=0;j<n;j++)
{
str="\0";
while(1)
{

ch=getchar();
if(ch=='\n')break;
str+=ch;
}
//		cout<<"1"<<str<<endl;
s1[j]=str;
mp[str]++;
str="\0";
while(1)
{
ch=getchar();
if(ch=='\n')break;
str+=ch;
}
//		cout<<"2"<<str<<endl;
s2[j]=str;

}

cin>>m;
getchar();
res=-1;
for(j=0;j<m;j++)
{
str="\0";
while(1)
{
ch=getchar();
if(ch=='\n'||ch==EOF)break;
str+=ch;
}
//	cout<<"3"<<str<<endl;
if(mp[str]>0)
{
mp[str]++;
if(mp[str]>res)res=mp[str];
}
}
flag=false;
k=0;
for(j=0;j<n;j++)
{
if(mp[s1[j]]==res)k++;
if(k==2){flag=true;break;}
}
if(flag)cout<<"tie"<<endl;
else{
for(j=0;j<n;j++)
if(mp[s1[j]]==res)
{
cout<<s2[j]<<endl;
break;
}
}

}
}``````
Input:

Code: Select all

``````3

3
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
John Smith
independent
6
John Smith
Marilyn Manson
Jane Doe
John Smith
Marilyn Manson
John Smith

3
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
John Smith
independent
6
John Smith
Marilyn Manson
Marilyn Manson
Jane Doe
John Smith
Marilyn Manson

3
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
John Smith
independent
6
John Smith
Marilyn Manson
Marilyn Manson
John Smith
Marilyn Manson
John Smith

``````
Output:

Code: Select all

``````independent

Rhinoceros

tie
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10374 - Election

Input:

Code: Select all

``````1

2
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
1
asdf``````
AC output:

Code: Select all

``tie``
Check input and AC output for thousands of problems on uDebug!

Achilies_Saiful_Buet
New poster
Posts: 16
Joined: Wed Mar 28, 2012 7:24 pm

### Re: 10374 - Election

Brianfry boss i checked ur testcases in uva toolkit but they give the same output as mine...!!!Nevertheless i tried to change my code according to ur suggestion but it is still wa!!!plz help

Code: Select all

``````#include<iostream>
#include<string>
#include<map>
#include<cstdio>

using namespace std;

string s1[32],s2[32];
int main()
{
//	freopen("10374in.txt","r",stdin);
int n,m,i,j,res,k,t;
char ch;
string str;
map<string,int>mp;
bool flag,check=false;
cin>>t;

for(i=0;i<t;i++)
{
if(check)cout<<endl;
if(!check)check=true;
mp.clear();
cin>>n;
getchar();
for(j=0;j<n;j++)
{
str="\0";
while(1)
{

ch=getchar();
if(ch=='\n')break;
str+=ch;
}
//		cout<<"1"<<str<<endl;
s1[j]=str;
mp[str]++;
str="\0";
while(1)
{
ch=getchar();
if(ch=='\n')break;
str+=ch;
}
//		cout<<"2"<<str<<endl;
s2[j]=str;

}

cin>>m;
getchar();
res=-1;
for(j=0;j<m;j++)
{
str="\0";
while(1)
{
ch=getchar();
if(ch=='\n'||ch==EOF)break;
str+=ch;
}
//	cout<<"3"<<str<<endl;
if(mp[str]>0)
{
mp[str]++;
if(mp[str]>res)res=mp[str];
}
}
flag=false;
k=0;
for(j=0;j<n;j++)
{
if(mp[s1[j]]==res)k++;
if(k==2){flag=true;break;}
}
if(res==-1)cout<<"tie"<<endl;
else if(flag)cout<<"tie"<<endl;
else{

for(j=0;j<n;j++)
if(mp[s1[j]]==res)
{
cout<<s2[j]<<endl;
break;
}
}

}
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10374 - Election

getchar();
Use
while(getchar()!='\n');

That way your code works with trailing spaces.
Check input and AC output for thousands of problems on uDebug!

zitu_cuet
New poster
Posts: 1
Joined: Sat Dec 15, 2012 8:45 am

### Re: 10374 - Election

Getting WA.

Code: Select all

``````#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<limits>
#include<vector>
#include<stack>
#include<string>
#include<deque>
#include<set>
#include<list>
#include<bitset>
#include<ctime>
#include<functional>
#include<numeric>
#include<cfloat>
#include<sstream>
#include<complex>
#include<queue>
#include<cstring>
#include<stdexcept>
#include<utility>
#include<map>
#include<fstream>
#include<iomanip>
#include<cassert>
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
#define inf (1<<30)-1
#define SIZE 100000001
#define pi 3.14159265358979323846
#define even(a) ((a)%2==0)
#define odd(a) ((a)%2==1)
const double E = 2.7182818284590452353602874713527;
using namespace std;
#define eps 1e-14
map<string,string>mp,mp2;
map<string,long>mp1,mp3;
char ch[10000],ch1[10000],st[10000];
int main()
{
char c;
long i,j,num,y,l,mx,test,n,p,len,r;
scanf("%ld",&test);
for(i=0;i<test;i++)
{
if(i>0)
printf("\n");
y=mx=n=p=0;
scanf("%ld",&num);
getchar();
for(j=0;j<num;j++)
{
gets(st);
len=strlen(st);
for(r=0;r<len;r++)
{
if(st[r]!=' ')
{
ch[p]=st[r];
p++;
}
}
ch[p]=NULL;
p=0;
gets(st);
len=strlen(st);
for(r=0;r<len;r++)
{
if(st[r]!=' ')
{
ch1[p]=st[r];
p++;
}
}
ch1[p]=NULL;
p=0;
mp[ch]=ch1;
mp3[ch]=1;
}
scanf("%ld",&num);
getchar();
p=0;
for(j=0;j<num;j++)
{
gets(st);
len=strlen(st);
for(r=0;r<len;r++)
{
if(st[r]!=' ')
{
ch[p]=st[r];
p++;
}
}
ch[p]=NULL;
p=0;
if(mp3[ch]!=0)
{
n=1;
l=++mp1[mp[ch]];
if(l>=mx)
{
if(l!=mx)
{
y=1;
mp2["res"]=mp[ch];
mx=l;
}
else
{
y=0;
}
}
}
}
if(y==0||n==0)
{
printf("tie\n");
}
else
cout<<mp2["res"]<<endl;
mp.clear(),mp1.clear(),mp2.clear(),mp3.clear();
}
return 0;
}

``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10374 - Election

Try your code on the sample input with a couple of extra trailing spaces on the lines with the numbers.
Check input and AC output for thousands of problems on uDebug!

kier.guevara
New poster
Posts: 30
Joined: Thu Jul 19, 2012 11:24 pm

### Re: 10374 - Election

Code: Select all

``````AC
``````
What are the critical inputs here? I tried all the test case here but I still got WA. Help please
Last edited by kier.guevara on Wed Apr 24, 2013 11:46 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10374 - Election

From uhunt:
AKJ88> @kier.guevara In my program I used gets instead of cin. I tried changing your code and using gets in it as well and it got AC. I don't know why but this is what happened!
AKJ88> I didn't change anything else, just replacing cin with gets and scanf.
Check input and AC output for thousands of problems on uDebug!