Last active
July 24, 2019 23:42
-
-
Save Silva97/4dd5a74ed7309b8093360c6db2d3aee5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************** | |
* Resolução para o problema: https://www.urionlinejudge.com.br/judge/pt/problems/view/1026 | |
* Por Luiz Felipe - https://github.com/Silva97 | |
********************/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
char* utostr(char *str, unsigned int n); | |
char output[BUFSIZ]; | |
int main(){ | |
unsigned int a, b; | |
char input[65], *p, *outp = output; | |
while(fgets(input, 64, stdin) != NULL){ | |
a = strtoul(input, &p, 10); | |
if(p == input) break; | |
b = strtoul(p + 1, NULL, 10); | |
outp = utostr(outp, a ^ b); | |
*outp++ = '\n'; | |
*outp = '\0'; | |
input[0] = '\0'; | |
if(outp - output > BUFSIZ - 128){ | |
printf("%s", output); | |
output[0] = '\0'; | |
outp = output; | |
} | |
} | |
if(output[0]) | |
printf("%s", output); | |
return 0; | |
} | |
char* utostr(char *str, unsigned int n){ | |
char *ptr = str, *p, c; | |
do { | |
*ptr++ = (n % 10) + '0'; | |
} while(n = n / 10); | |
*ptr = '\0'; | |
p = ptr - 1; | |
while(str < p){ | |
c = *str; | |
*str++ = *p; | |
*p-- = c; | |
} | |
return ptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment