
The following code gets tons of compiling errors from the online judge.
Why does the library remain non-standard for this long?
[cpp]
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
bool judge(const string &s) {
string temp(s);
string::iterator newEnd = remove(temp.begin(), temp.end(), '-');
temp.erase(newEnd, temp.end());
if (temp.size() != 10)
return false;
else {
const char* number = temp.c_str();
int sum = 0;
size_t index = 0;
for (; index != (temp.size()-1); ++index) {
if (isdigit(number[index]) != 0) {
sum += (10 - index) * (number[index] - '0');
continue;
}
else
return false;
}
sum += (number[index] == 'X') ? 10 : (number[index] - '0');
if ((sum % 11) == 0)
return true;
else
return false;
}
}
int main() {
string input;
string::iterator newEnd;
while (getline(cin, input)) {
newEnd = remove(input.begin(), input.end(), ' ');
input.erase(newEnd, input.end());
if (judge(input) == true)
cout << input << " is correct." << endl;
else
cout << input << " is incorrect." << endl;
}
return 0;
}
[/cpp]
Here are the compiler error messages (the real list is more than ten times longer):
01088009_24.c:3: syntax error before `a'
In file included from /usr/include/_G_config.h:44,
from /usr/include/libio.h:32,
from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/streambuf.h:36,
from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/iostream.h:31,
from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/iostream:6,
from 01088009_24.c:12:
/usr/include/gconv.h:72: type specifier omitted for parameter
/usr/include/gconv.h:72: parse error before `*'
....