Lack of logic getting wrong answer

I dont know why iam getting wrong answer in this problem.Below is the link to the problem:

and my solution:

#include<iostream>
#include<cstdio>
#include<cstring>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);


using namespace std;

int main()
{
	FAST_IO
int T;
char S[315];
scanf("%d",&T);
while(T--)
{
	scanf("\n");
	scanf("%[^\n]%*c", S);

	int arr[26],i;
	
	for(int i=0;i<26;i++)
	    arr[i]=0;
	    
	for(i=0;i<strlen(S);i++)
	{
	
		if(S[i]>=97 && S[i]<=122)
		{
			arr[S[i]%97]++;
		}
		else if(S[i]>=65 && S[i]<=90)
		{
			arr[S[i]%65]++;
		}
	}
int flag=0;
for(i=0;i<26;i++)
{
	if(arr[i]==0)
	{	
	    printf("%c\n",i+97-32);
	    flag=1;
		break;
	}	
}

if(flag==0)
	puts("~");

}
    return 0;
}




Is there anything preventing a testcase like:

4
aaa
   
bbb
aaa

(the third line/ second question consists of 3 spaces)?

yes its preventing the all spaces.

I have modified the code now which accepts spaces also but still getting wrong answer.

//#include<iostream>
#include<stdio.h>
#include<string.h>
//#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);


//using namespace std;

int main()
{
//	FAST_IO
int T;
char S[316];
scanf("%d",&T);
while(T--)
{
	//scanf("\n");
	//scanf("%[^\n]%*c", S);
	//fgets(S,315,stdin);
	getchar();
	gets(S);
	int arr[26]={0},i,flag=0;
	for(i=0;i<strlen(S);i++)
	{
	
		if(S[i]>=97 && S[i]<=122)
		{
			arr[S[i]%97]++;
		}
		else if(S[i]>=65 && S[i]<=90)
		{
			arr[S[i]%65]++;
		}
	}

for(i=0;i<26;i++)
{
	if(arr[i]==0)
	{	printf("%c\n",i+65);
		flag=1;
		break;
	}	
}

if(flag==0)
	puts("~");


}
    return 0;
}


He found the solution: CodeChef: Practical coding for everyone

1 Like