Tuesday, January 21, 2020

Codeforces 339A Helpful Maths Solution in C


  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. int i,a,b,c,x,z;
  6. char n[200];
  7. scanf("%s",&n);
  8. x=strlen(n);
  9. i=0;a=0;b=0;c=0;
  10. while (i<x)
  11. {
  12. if (n[i]=='1') a++;
  13. else if (n[i]=='2') b++;
  14. else if (n[i]=='3') c++;
  15. i+=2;
  16. }
  17. i=0;z=0;
  18. while (i<a)
  19. {
  20. if (i==0) printf("1");
  21. else printf("+1");
  22. i++;
  23. z++;
  24. }
  25. i=0;
  26. while (i<b)
  27. {
  28. if (z==0) printf("2");
  29. else printf("+2");
  30. i++;
  31. z++;
  32. }
  33. i=0;
  34. while (i<c)
  35. {
  36. if (z==0) printf("3");
  37. else printf("+3");
  38. i++;
  39. z++;
  40. }
  41. printf("\n");
  42. return 0;
  43. }

No comments:

Post a Comment

Codeforces 131A cAPS lOCK Solution in C

#include <stdio.h> int main () { char ch [ 106 ]; int i , j , ck = 1 ; scanf ( "%s" , ch ); ...