Algorithm
Problem Name: 2 AD-HOC - beecrowd | 2569
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2569
The 7 x 1 Witch
By Ricardo Martins, IFSULDEMINAS Brazil
Timelimit: 1
Dona Clotilde is a very nice lady who lives in a village, in house which number is 71. It's not known why, but she had a reputation for being a witch. Clotilde was eager to watch a football game. One day, she bought a liquid to clean silver. With this, she won a coupon that gave her a number to compete for a ticket to the 2014 World Cup semifinal at Mineirão, the game between Germany and Brazil. The raffle happened and she won the ticket. Clotilde went to the game, Brazil lost 7 x 1, and everyone in the village thought that Brazil had lost that way because of her, poor thing! Her hacking nephew, San Tanaz, taking her aunt's pains, decided to create a computer virus that interfered with mathematical calculations, so that anything involving number 7 in the accounts would become 0.
For example:
3 + 4 = 0
33 + 44 = 0
17 + 11 = 21
8 x 9 = 2
12 x 7 = 0
8 + 9 = 10
Input
Composed of a single line with two integers a and b (0 < a, b < 10000), separated by a sum or multiplication operator.
Output
An integer corresponding to the result of the account, after the virus.
Input Samples | Output Samples |
3 + 4 |
0 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <string.h>
void retiraZero(const char *, char *);
long int StrToInt(char *str);
void IntToStr(unsigned short, char *);
int main (void)
{
char operandoA[11], operandoB[11], resultadoStr[100];
char operandoASem7[11], operandoBSem7[11], resultadoStrSem7[100];
long int resultado;
char operacao;
scanf("%s %c %s", operandoA, &operacao, operandoB);
retiraZero(operandoA, operandoASem7);
retiraZero(operandoB, operandoBSem7);
if (operacao == '+')
resultado = StrToInt(operandoASem7) + StrToInt(operandoBSem7);
else if (operacao == 'x')
resultado = StrToInt(operandoASem7) * StrToInt(operandoBSem7);
sprintf(resultadoStr, "%ld", resultado);
retiraZero(resultadoStr, resultadoStrSem7);
printf("%ld\n", StrToInt(resultadoStrSem7));
}
void retiraZero(const char *operando, char *operandoSem7)
{
unsigned short i = 0;
unsigned short j = 0;
while (operando[i])
{
if (operando[i] == '7')
operandoSem7[j++] = '0';
else
operandoSem7[j++] = operando[i];
i++;
}
operandoSem7[j] = '\0';
}
long int StrToInt(char *str)
{
long int i, multiplicador = 1, numero = 0;
for(i = strlen(str) - 1; i >= 0; i--, multiplicador *= 10)
numero += (str[i] - 48) * multiplicador;
return numero;
}
Copy The Code &
Try With Live Editor
Input
#2 Code Example with Python Programming
Code -
Python Programming
s=input().split()
n1=str(s[0].replace('7','0'))
op=s[1]
n2=str(s[2].replace('7','0'))
res=str(int(n1)+int(n2)) if op=='+' else str(int(n1)*int(n2))
res=int(res.replace('7','0'))
print(res)
Copy The Code &
Try With Live Editor
Input