Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main() {
  5. double s;
  6. double drob = 0, counter = 0, dr_counter = 1;
  7. int dot = 0, save = 0;
  8.  
  9. while((s = getchar_unlocked()) != EOF) {
  10. double num = s - '0';
  11. if (isdigit(s)) {
  12. save = 1;
  13. if (dot == 0) {
  14. counter *= 7;
  15. counter += num;
  16. } else {
  17. drob *= 7;
  18. drob += num;
  19. dr_counter *= 7;
  20. }
  21. }
  22. if (isspace(s) && save == 1) {
  23. drob = drob / dr_counter;
  24. if ((drob) == (int)(drob)) {
  25. printf("%d\n", (int)(counter + drob));
  26. } else {
  27. printf("%.10g\n", counter + drob);
  28. }
  29. counter = 0, drob = 0, dr_counter = 1;
  30. dot = 0, save = 0;
  31. }
  32. if (s == '.') {
  33. save = 1;
  34. dot = 1;
  35. }
  36. }
  37. if (counter + drob != 0) {
  38. drob = drob / dr_counter;
  39. if (save == 1) {
  40. if ((drob) == (int)(drob)) {
  41. printf("%d\n", (int)(counter + drob));
  42. } else {
  43. printf("%.10g\n", counter + drob);
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement