muntasir007

Untitled

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