Page 2 of 3

Re: 10374 - Election

Posted: Mon Jan 25, 2010 8:22 am
by naseef_07cuet

Code: Select all

//Code Removed After AC!

WA: 10374 - Election

Posted: Fri May 07, 2010 10:48 pm
by Mehadi
I Got WA again & again.Can anyone help me.What's problem in my code.
Thanks in advance.

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;
}

Re: 10374 - Election

Posted: Thu Sep 01, 2011 7:46 pm
by Shafaet_du
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.

Re: 10374 - Election

Posted: Tue Oct 18, 2011 6:19 pm
by plamplam
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/

Re: 10374 - Election

Posted: Sun Nov 06, 2011 9:05 pm
by shakil ahmed
WHY runtime error?????plz help.i am very new in this site.thanx................:) :cry:

#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;
}

Re: 10374 - Election

Posted: Tue May 01, 2012 1:47 pm
by Achilies_Saiful_Buet
Having WA!! WA!! today...what's wrong with this now....plz help!! with test cases

Re: 10374 - Election

Posted: Wed May 02, 2012 1:22 am
by brianfry713
The outputs of two consecutive cases will be separated by a blank line.

Re: 10374 - Election

Posted: Wed May 02, 2012 12:41 pm
by Achilies_Saiful_Buet
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

Re: 10374 - Election

Posted: Wed May 02, 2012 11:10 pm
by brianfry713
Input:

Code: Select all

1

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

Code: Select all

tie

Re: 10374 - Election

Posted: Thu May 03, 2012 10:39 pm
by Achilies_Saiful_Buet
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;
				}
		}


	}
}

Re: 10374 - Election

Posted: Fri May 04, 2012 9:22 pm
by brianfry713
Instead of writing:
getchar();
Use
while(getchar()!='\n');

That way your code works with trailing spaces.

Re: 10374 - Election

Posted: Sat Dec 15, 2012 8:52 am
by zitu_cuet
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;
}


Re: 10374 - Election

Posted: Sat Dec 15, 2012 11:32 am
by brianfry713
Try your code on the sample input with a couple of extra trailing spaces on the lines with the numbers.

Re: 10374 - Election

Posted: Tue Apr 23, 2013 11:44 pm
by kier.guevara

Code: Select all

AC
What are the critical inputs here? I tried all the test case here but I still got WA. Help please

Re: 10374 - Election

Posted: Wed Apr 24, 2013 1:30 am
by brianfry713
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.