Can someone help identify bugs in my code? Or point me towards a few helpful test cases?
#include<stdio.h>
int main()
{
int t,i,count;
char ch;
scanf("%d",&t);
scanf("%c",&ch);
while(t–)
{
int a[125]={0};
scanf("%c",&ch);
while(ch!='\n')
{
a[ch]++;
scanf("%c",&ch);
}
count=0;
for(i=65;i<=90;i++)
{
count+=((a[i]+1)/2);
}
for(i=97;i<=122;i++)
{
count+=((a[i]+1)/2);
}
printf("%d\n",count);
}
return 0;
}
please , tell me the problem with the code.
My code runs within time produces desired results uses the obvious login but still i am getting wrong answer!! please could someone help me with my following code:- http://www.codechef.com/viewsolution/4896723
This is getting a WA respose.
use POSIX;
$,=",";
my $T=<>;
chomp($T);
while($T--){
my $str=<>;
chomp($str);
my $ans=0;
my %charCount;
for(my $i=0;$i<length($str);$i++){
$charCount{substr($str,$i,1)}++;
}
for(values %charCount){
$ans+=ceil($_/2);
}
print $ans . "\n";
}
Can someone help with this.
#include<stdio.h>
#include<string.h>
int main()
{
int t,j,i,count;
char a[201];
scanf("%d",&t);
while(t–)
{
count = 0;
scanf("%s",a);
for(i=0;i<strlen(a)-1;i++)
{
if(a[i]!=’’)
{
for(j=i+1;j<strlen(a);j++)
{
if(a[i]==a[j])
{
a[i]=’’;
a[j]=’*’;
count++;
}
}
}
}
printf("%d\n",strlen(a)-count);
}
return 0;
}
what is wrong with this solutions works fine on my pc but gives wrong answer here. please help.
Why i’m getting wrong answer?
My code is
#include<stdio.h>
int check(int [],char);
int main()
{
int T,i,A[205]={0},cnt=0,x;
char ch[205];
scanf("%d",&T);
while(T–)
{ A[0]=-1;
cnt=0;
scanf("%s",ch);
for(i=0;ch[i]!=’\0’;i++)
{ x=check(A,ch[i]);
if(x)
{
cnt++;
}
}
for(i=0;A[i]!=-1;i++)
{
if(A[i]!=0)
cnt++;
}
printf("%d",cnt);
}
return 0;
}
int check(int A[],char c)
{
int x,i;
for(i=0;A[i]!=-1;i++)
{
if(A[i]==c)
{
A[i]=0;
return 1;
}
}
A[i]=c;
A[i+1]=-1;
return 0;
}
I have tried my best to debug this code but can’t find the test cases am failing in , please correct my mistakes , it’s not very lengthy :
Can you tell me why this soln is wrong ?
It’s working perfectly fine in my m/c for all sorts of i/p
https://www.codechef.com/viewsolution/8339530
use someother value instead of “0” when u are marking, your loop is ending when its reaching any index where a[i]==0(0==NULL). -1 will work.
I have implemented the following solution. https://www.codechef.com/viewsolution/8932461
I am not sure in which test case it is failing… ? It worked for all the inputs provided in the Question. Can someone please point out the error in the logic.