Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define true 1
- #define false 0
- int isSeparator(char c);
- int isNumber(char c);
- int isNegative(char c);
- int main()
- {
- char c;
- short check, negative;
- int int_max;
- unsigned long long number = 0;
- check = true;
- negative = false;
- int_max = 2147483647;
- do
- {
- c=getchar();
- if (isSeparator(c))
- {
- check = true;
- putchar(c);
- }
- if(check == false)
- {
- putchar(c);
- number = 0;
- }
- else if (isNumber(c) || isNegative(c))
- {
- number = 0;
- negative = false;
- if (isNegative(c))
- {
- c = getchar();
- negative = true;
- }
- while (c >= '0' && c <= '9' && number <= ((int_max / 10)- (c - '0')))
- {
- number = number*10 + (c - '0');
- c = getchar();
- }
- if (negative == true)
- number = -number;
- if (isSeparator(c))
- putchar(c);
- else if (isNumber(c) && negative == true)
- {
- printf("%ld", number);
- putchar(c);
- check = false;
- }
- else if (number != 0)
- {
- printf("%ld", number);
- putchar(c);
- check = false;
- number = 0;
- }
- else
- {
- putchar(c);
- check = false;
- number = 0;
- }
- }
- else if(!isSeparator(c)){
- putchar(c);
- check=false;
- }
- } while (c != EOF);
- return 0;
- }
- int isSeparator(char c)
- {
- if (c == ' ' || c == ',' || c == '\t' || c == '\n' || c == EOF)
- return 1;
- else
- return 0;
- }
- int isNumber(char c)
- {
- if (c >= '0' && c <= '9')
- return 1;
- else
- return 0;
- }
- int isNegative(char c)
- {
- if (c == '-')
- return 1;
- else
- return 0;
- }
Add Comment
Please, Sign In to add comment