Error gives in codeforces compiler but in vscode gives answer in same condition

Revision en1, by Codersaurus, 2022-11-23 19:14:24

Hello friends, I'm newbie to codeforces and these problems by using c language.and When I submit my code It always says that "Wrong answer on test 1". But when I run my code on vscode succesfully and it gives correct output in A. Helpful Maths problem. And this is my code. It's little bit lenthy. But it works correctly.I don't why i'm getting that error. This link helps you to go my answer ~~~~~ #include <stdio.h> #include <string.h>       int main(void){ char mystring[101]; int a,b,c; scanf("%s",mystring); for(int i = 0; i < strlen(mystring);i++){ if (mystring[i]== '1'){ a++; } else if (mystring[i]== '2'){ b++; } else if (mystring[i]== '3'){ c++; }
} //printf("%d\n %d\n %d",a,b,c); for(int j = 0; j < strlen(mystring);){ if (j < a){ printf("%c",'1');
} else if ( j < a + b && j >= a){ printf("%c",'2'); } else if ( j < a + b + c && j >= b){ printf("%c",'3'); } j++; if ( j <= a + b + c -1) printf("%c",'+');   } printf("\n");
    } ~~~~~

Tags #greedy, #strings, #sortings, #implementation, #newbie

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Codersaurus 2022-11-23 19:32:20 1018
en1 English Codersaurus 2022-11-23 19:14:24 1554 Initial revision (published)