I'm currently doing this problem: http://coj.uci.cu/24h/problem.xhtml?pid=1102
which is actually a very easy problem, just that I have a slight problem, how do I store 1000 digit integers? Here is my current code, although the online judge keeps saying wrong answer because my code can't store 1000 digit integers.
#include <stdio.h>
#include <iostream>
usingnamespace std;
int main() {
unsignedlong x, r;
for (;;) {
scanf("%lu", &x);
r=x%11;
if (x==0) {
break;
}
if (r==0){
printf("%lu", x); printf("%s\n", " is a multiple of 11.");
}
else{
printf("%lu", x); printf("%s\n", " is not a multiple of 11.");
}
}
}
Either use a bignum library if you can find no other way of doing it (seems like a bad idea) or store the characters in a string and use a more advanced algorithm to determine if it is a multiple of eleven.
#include <iostream>
#include <string>
int main()
{
std::string number;
std::cin >> number;
int result = 0;
for(int i = 0; i < number.size(); ++i) {
int digit = number[i] - '0';
//Do calculations with current digit
}
//Use result to determine if it is divisible by 11;
}