Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void) {
  6.     int x;
  7.     double ans = 0, multipl = 1;
  8.     int digit = 0, integer = 1;
  9.     while ((x = getchar()) != EOF) {
  10.         if (x == '.') {
  11.             integer = 0;
  12.         } else {
  13.             if (isdigit(x)) {
  14.                 digit = 1;
  15.                 if (integer == 1) {
  16.                     ans = ans * 7 + (x - '0');
  17.                 } else {
  18.                     multipl /= 7;
  19.                     ans += multipl * (x - '0');
  20.                 }
  21.             } else {
  22.                 if (digit == 1) {
  23.                     printf("%.10g\n", ans);
  24.                     ans = 0; multipl = 1;
  25.                     digit = 0; integer = 1;
  26.                 }
  27.             }
  28.         }
  29.     }
  30.     if (digit == 1) {
  31.         printf("%.10g\n", ans);
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement