|
|
back to boardWhy could I POSSIBLY have a wrong answer on the FIRST test?! Posted by Zrutor 24 Jan 2010 03:16 I checked my program, and I'm pretty sure that it gives the correct answers for the sample input/output, and for all the tests given on this forum. I also went to the page of NEERC 2002 and downloaded their test examples, and everything seems to be correct. I tried ending output with or without a newline('\n'), and I still can't figure out why I could possibly be getting a wrong answer three times in a row. Please give me some advice as to where my problem is. Maybe it is someting small? Maybe I misread something in the problem statement? Anyway, here's my program(I'm sure the code is pretty bad, but keep in mind that I don't have much experience with these sorts of problems): #include <iostream> #include <iomanip> using namespace std; int main() { int A[10002]; long int pos = 0;
cin.unsetf(ios::skipws);
do { char input[3];
cin >> input[0];
if(input[0] == '\n') break;
cin >> input[1];
input[2] = 0;
A[pos] = (int) strtol(input, (char **) input + 2 * sizeof(char), 16); pos++;
} while(1);
int current; int key;
char input[3]; input[0] = 'C'; input[1] = '9'; input[2] = 0;
cin >> input[0] >> input[1]; key = (int) strtol(input, (char **) input + 2 * sizeof(char), 16); key ^= 32;
for(int i = 0; i < pos; i++) { cout << hex << uppercase << setfill('0') << setw(2) << key;
cin >> input[0] >> input[1];
current = (int) strtol(input, (char **) input + 2 * sizeof(char), 16);
key = ((key) ^ (A[i])) ^ (current); }
cout << hex << uppercase << setfill('0') << setw(2) << key << "\n";
return 0; } Please help! Any advice will be appreciated! |
|
|