fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int testcase;
  5. scanf("%d",&testcase);
  6. while(testcase--){
  7. int size,i,flag=0,count=0,j,c=0;
  8. scanf("%d",&size);
  9. char str[size];
  10. scanf("%s",&str);
  11. for(i=0;i<size;i++){
  12. if(str[i]=='T' && c=0){
  13. printf("invalid\n");
  14. }
  15. else if(str[i]=='H'){
  16. c++;
  17. for(j=i+1;j<size;j++){
  18. if(str[j]==str[i]){
  19. flag=1;
  20. break;
  21. }
  22. }
  23. else if(str[i]=='T'){
  24. c++;
  25. for(j=i+1;j<size;j++){
  26. if(str[j]==str[i]){
  27. flag=1;
  28. break;
  29. }
  30. }
  31. if(flag==1)
  32. break;
  33. }
  34. if(flag==1)
  35. printf("invalid\n");
  36. else
  37. printf("valid\n");
  38.  
  39. }
  40. // your code goes here
  41. return 0;
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 9416KB
stdin
6
18
..H..T...HTH....T.
3
...
10
H..H..T..T
2
HT
11
.T...H..H.T
7
H..T..H
compilation info
prog.c: In function ‘main’:
prog.c:10:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[(sizetype)(size)]’ [-Wformat=]
   scanf("%s",&str);
           ^
prog.c:12:23: error: lvalue required as left operand of assignment
    if(str[i]=='T' && c=0){
                       ^
prog.c:23:4: error: expected ‘}’ before ‘else’
    else if(str[i]=='T'){
    ^~~~
prog.c:7:21: warning: unused variable ‘count’ [-Wunused-variable]
   int size,i,flag=0,count=0,j,c=0;
                     ^~~~~
prog.c:42:1: error: expected declaration or statement at end of input
 }
 ^
stdout
Standard output is empty