okay I found the solution there was a memory leak which happens due to multiple buffer reader objects sharing the same input stream so I declared a static field like
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
and it worked fine
check the logic the brackets are a bit messed up .its showing runtime error on codechef but working well on codeblocks
Hello, my python code is working for custom input case but is not getting accepted and showing âWrong Answerâ.Can anyone tell me my mistake, please?
Thanks in advance!
[Pythoncode]:
https://www.codechef.com/viewsolution/23700466
1 Like
t = int(input())
while(t>0):
n = int(input())
if(n!=0):
str1 = ""
str2 = ""
str1 = input()
count1 = 1
count2 = 0
n -= 1
if(n>=1):
while(n>0):
str2 = input()
if(str2 != str1):
count2 += 1
elif(str2 == str1):
count1 += 1
n -= 1
if(count1 > count2):
print(str1)
elif(count1 == count2):
print("Draw")
else:
print(str2)
t -= 1
else:
print("Draw")
t -= 1
Can someone provide me test case that fails, seems to be working all the time
Itâs not getting accepting I am getting Wrong Answer, also the problem needs to be clear with n = 0 as inout the output should be draw. It could have been clear when no teams are given as the question says there are atleast two teams, highly contradicting.
i do not know much about python
But there are maps in c++ which have good application in the respected problem.
You can check if there exists some ds in python functioning similiar to maps in c++
There might be coz python is such a broad language.
Try this TT bro:
It may help
Sample input:
2
1
cbt
0
Sample output
cbt
Draw
#include
using namespace std;
int main(){
int testcases;
cin >> testcases;
while(testcases>0){
int numofentries,firstteamwins=0,secondteamwins=0;
cin >> numofentries;
string firstteam;
string secondteam;
string answer;
if(numofentries>0){
cin >> firstteam;
firstteamwins++;
for(int i=0;i<numofentries-1;i++){
string winstring;
cin>> winstring;
if(winstring==firstteam){
firstteamwins++;
}
else{
secondteam=winstring;
secondteamwins++;
}
}
if(firstteamwins>secondteamwins){
answer=firstteam;
}
else if(secondteamwins>firstteamwins){
answer=secondteam;
}
else if(secondteamwins==firstteamwins){
answer=âDrawâ;
}
cout << answer<<"\n";
}
else{
cout << âDrawâ<<"\n";
}
testcasesâ;
}
return 0;
}
This is my approach.
It should be clarified what should be the output in case of n=0.
Caused me lots of wa on this question.
Simple solution in CPP:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--){
int n1;
cin>>n1;
string str1="",str2="";
int c1=0,c2=0;
while(n1--)
{
string str;
cin>>str;
if( str1 == "" or str1 == str ){
str1 = str;
c1 = c1+1;
}else{
str2 = str;
c2 = c2+1;
}
}
if(c1 == c2){
cout<<"Draw"<<endl;
}else if( c1>c2){
cout<<str1<<endl;
}else{
cout<<str2<<endl;
}
}
return 0;
}
my solution in cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
long long int t;
cin>>t;
while(tâ){
long long int n,cnt1=0,cnt2=0;
cin>>n;
vectorv(n);
for(auto &x:v){cin>>x;}
sort(v.begin(),v.end());
for(long long int i=0;i<n;i++){
if(v[0]==v[i]){
cnt1++;
}
else{
cnt2++;
}
}
if(cnt1==cnt2){
cout<<"Draw"<<endl;
}
else if(cnt1>cnt2){
cout<<v[0]<<endl;
}
else{
cout<<v[n-1]<<endl;
}
}
return 0;
}