muntasir007

Untitled

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