Skip to content

Instantly share code, notes, and snippets.

@antonio-abrantes
Created July 2, 2016 03:26
Show Gist options
  • Save antonio-abrantes/ad4eca796e84ab0ca7f59caa2acf66d8 to your computer and use it in GitHub Desktop.
Save antonio-abrantes/ad4eca796e84ab0ca7f59caa2acf66d8 to your computer and use it in GitHub Desktop.
Uri 1728 - (Accepted)
/* Problema Difícil de Acreditar, Mas é Verdade! - Uri 1728
Status - Accepted
By Antonio Abrantes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i, j, num1, num2, result, soma, sair = 0, posi;
char strNum1[15], strNum2[15], strResult[15], temp1[15], temp2[15], temp3[15];
char equacao[100], aux[100];
while(1){
scanf("%s", equacao);
posi = 0;
soma = 0;
for(i = 0; i < strlen(equacao); i++){
if(equacao[i] == '+'){
strNum1[i] = '\0';
posi = i;
break;
}
strNum1[i] = equacao[i];
}
strcpy(aux, equacao+posi+1);
strcpy(equacao, aux);
for(i = 0; i < strlen(equacao); i++){
if(equacao[i] == '='){
strNum2[i] = '\0';
posi = i;
break;
}
strNum2[i] = equacao[i];
}
strcpy(aux, equacao+posi+1);
strcpy(strResult, aux);
//Inverte as strings
j = strlen(strNum1) - 1;
for(i = 0; i < strlen(strNum1); i++){
temp1[i] = strNum1[j];
j--;
}
temp1[strlen(strNum1)] = '\0';
j = strlen(strNum2) - 1;
for(i = 0; i < strlen(strNum2); i++){
temp2[i] = strNum2[j];
j--;
}
temp2[strlen(strNum2)] = '\0';
j = strlen(strResult) - 1;
for(i = 0; i < strlen(strResult); i++){
temp3[i] = strResult[j];
j--;
}
temp3[strlen(strResult)] = '\0';
//Converte strings para inteiros
num1 = atoi(temp1);
num2 = atoi(temp2);
result = atoi(temp3);
if(num1 == 0 && num2 == 0 && result == 0){
sair = 1; //Verifica condição de saida
}
soma = num1 + num2;
if(soma == result){
printf("True\n");
}else{
printf("False\n");
}
if(sair == 1){
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment