Back to General discussions forum
i dont know where is the problem.. example was ok.. but when i tried to test, i got different value..
first one i use int, but i changed because i need more data value max.. but when i use long, the problem still appears
#include <stdio.h>
int main() {
long nilai, hasil, modular,sisa;
char tanda;
scanf("%ld", &hasil);
while(1) {
scanf(" %c", &tanda);
if(tanda == '%') {
scanf("%ld", &modular);
break;
}
scanf("%ld", &nilai);
if(tanda == '*') {
hasil*= nilai;
}
else if ( tanda == '+') {
hasil += nilai;
}
}
sisa = hasil % modular;
printf("%ld\n", sisa);
return 0;
}
Hi Friend!
The problem text has a link to Modular Arithmetics
article. You need to read and understand it in order to solve this
problem.
Values are intentionally large so that no int
or long
can hold it. Some careless people use endless arithmetics (e.g.
in Python) but there is "advanced" version of the problem where even this won't help.
This problem requirres a bit of thinking and understanding, rather than dull coding.
okay admin, thank you
I'm not able to select a whole values as 1 input
when i tried to get input as usual like line=input().split() it only gives me 1st line and not other
plese help
try more input()
statements. each of them reads one line if I remember correctly.
looks tricky but i can try it