Guest User

Untitled

a guest
Apr 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #define true 1
  3. #define false 0
  4.  
  5. int isSeparator(char c);
  6. int isNumber(char c);
  7. int isNegative(char c);
  8.  
  9. int main()
  10. {
  11.   char c;
  12.   short check, negative;
  13.   int int_max;
  14.   unsigned long long number = 0;
  15.   check = true;
  16.   negative = false;
  17.   int_max = 2147483647;
  18.  
  19.   do
  20.     {
  21.       c=getchar();
  22.       if (isSeparator(c))
  23.     {
  24.     check = true;
  25.     putchar(c);
  26.     }
  27.       if(check == false)
  28.     {
  29.     putchar(c);
  30.     number = 0;
  31.     }
  32.       else if (isNumber(c) || isNegative(c))               
  33.     {
  34.       number = 0;
  35.       negative = false;
  36.       if (isNegative(c))
  37.         {
  38.           c = getchar();
  39.           negative = true;
  40.         }
  41.       while (c >= '0' && c <= '9' && number <= ((int_max / 10)- (c - '0')))
  42.         {
  43.           number = number*10 + (c - '0');      
  44.           c = getchar();                   
  45.         }
  46.       if (negative == true)
  47.         number = -number;
  48.       if (isSeparator(c))              
  49.         putchar(c);                
  50.       else if (isNumber(c) && negative == true)
  51.         {
  52.           printf("%ld", number);
  53.           putchar(c);
  54.           check = false;
  55.         }
  56.       else if (number != 0)
  57.         {
  58.           printf("%ld", number);
  59.           putchar(c);
  60.           check = false;
  61.           number = 0;
  62.         }
  63.       else 
  64.         {
  65.           putchar(c);
  66.           check = false;
  67.           number = 0;
  68.         }
  69.     }
  70.       else if(!isSeparator(c)){
  71.     putchar(c);
  72.     check=false;
  73.       }
  74.    
  75.      
  76.     } while (c != EOF);
  77.   return 0;
  78. }
  79.  
  80. int isSeparator(char c)
  81. {
  82.   if (c == ' ' || c == ',' || c == '\t' || c == '\n' || c == EOF)
  83.     return 1;
  84.   else
  85.     return 0;
  86. }
  87.  
  88. int isNumber(char c)
  89. {
  90.   if (c >= '0' && c <= '9')
  91.     return 1;
  92.   else
  93.     return 0;
  94. }
  95.  
  96. int isNegative(char c)
  97. {
  98.   if (c == '-')
  99.     return 1;
  100.   else
  101.     return 0;
  102. }
Add Comment
Please, Sign In to add comment