BUY1GET1 - Editorial

whats the problem with the following code???

http://www.codechef.com/viewsolution/1844213

@ritu2510 >> You are not supposed to print the “enter the number of test cases” thing here in the programs. There are testdata and your program is supposed to take input from standard input and give output on the standard output. It need not be “user friendly” in the output, it should just give correct output for each corresponding input.

UPD.

Moreover, you need not store all the input in an array and then display output at once. You should take an input and do the calculations and print the output and then take the next input and proceed in the same manner.
See, I modified your code: removed the “enter the number of test cases” thing and removed the array a[] into just a string a and it got Accepted. CodeChef: Practical coding for everyone

http://www.codechef.com/viewsolution/2058133
what is wrong with my solution?

Iam Getting wrong answer ,some might test cases might be missing pls suggest some typical test cases…

Can someone help identify bugs in my code? Or point me towards a few helpful test cases?

http://www.codechef.com/viewsolution/4663644

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:- CodeChef: Practical coding for everyone

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 :

http://www.codechef.com/viewsolution/7301396

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

can u please tell my mistake in this code…
https://www.codechef.com/viewsolution/8534920

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. CodeChef: Practical coding for everyone

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.

Why is my answer coming wrong?CodeChef: Practical coding for everyone
Please help

my solution

Can someone please tell me what’s wrong with my solution.

The only mistake is the small size of the array s.
Instead of 200 there should be 201. Simply fixing this gets AC:
http://www.codechef.com/viewsolution/1835761
(I should also add string.h library to get this compiled at C++)

If ‘A’ … ‘Z’ is 0 to 25, then it makes sense to have ‘a’ as 26 etc. 97-71 = 26, so it seems fine.

1 Like

ohkay…got it…removing the “enter the number of test cases” is helping…thanx!!
and yeah… storing it in an array was not required.

@vineetpaliwal : I made sure that every letter gets a unique index.(uncomment cout on line 42)If possible may I know the test cases where my code fails.