please tell me what’s wrong in this code . this code is running correctly and output is also coming right but when i try to submit it , it gives wrong answer.
include <stdio.h>
include <string.h>
void ans(char* str,int y){
int count=0;
char a=str[0];
for(int j=0;j<y+1;j++){
if(str[j]==a){
count++;
}
else{
printf(“%c”,a);
if(count!=1)
printf(“%d”,count);
count=1;
a=str[j];
}
}
return ;
}
int main() {
int t;
scanf(“%d”,&t);
int i=0;
while(i<t){
char str[100];
scanf(“%s”,str);
int y=strlen(str);
ans(str,y);
i++;
}
return 0;
}
Thanks , now this code is working perfectly . but how do you know that there is need of ‘\n’ because in the output there was no need of ‘\n’
@tamrakartanu04
cozz in the sample test case they have used t=1 , in this case we don’t need “\n”.
but for t>1 we do need “\n”.