muntasir007

Untitled

Feb 20th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main () {
  5.  
  6. char str[100];
  7. int cs=1;
  8. while (scanf("%s", str)) {
  9. if (str[0] == '#') return 0;
  10. else if (cs>1) printf("\n");
  11. int n = strlen(str) - 1;
  12. int zero = 1, ambi = 0, up = 0, down=0, no=0, doshomik = 0;
  13. for (; n>=0 ; n--) {
  14. if (str[n] == '.') {
  15. doshomik = 1;
  16. break;
  17. }
  18. else if (str[n] != '0' && zero == 1) {
  19. zero = 0;
  20. if (str[n] == '5') ambi++;
  21. else if (str[n] >= '0' && str[n] <= '4') down++;
  22. else up++;
  23. }
  24. else if (str[n] == '0') {
  25. if (zero) no++;
  26. else down++;
  27. }
  28. else if (str[n] >= '0' && str[n] <= '4') down++;
  29. else up++;
  30. }
  31. printf("Case %d:\n", cs++);
  32. if (doshomik) {
  33. printf("ROUND UP: %d\n", up);
  34. printf("ROUND DOWN: %d\n", down);
  35. printf("NO CHANGE: %d\n", no);
  36. printf("AMBIGUOUS: %d\n", ambi);
  37. }
  38. else {
  39. printf("ROUND UP: %d\n", 0);
  40. printf("ROUND DOWN: %d\n", 0);
  41. printf("NO CHANGE: %d\n", 0);
  42. printf("AMBIGUOUS: %d\n", 0);
  43. }
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment