Pairing Control problem

Back to Problem Solutions forum

Michael Gnedkovskii     2017-08-03 10:48:33

Hi there! I've solved the problem and the answer is the same as your checker gives. But it also says that my answer is wrong. Please, advise what should I do to make your checker think I really solved this problem? I wanted to attach a screenshot but it seems to be impossible, so I just copied the text from the screen.

Your answer is Wrong Expected answer was:

iqhaTi lLx XTkuQ6FMHWy B4uhZHtr I m2195hi9IISEHh1Asi3qv fmxFisznri4DKKw.

Your answer was: iqhaTi lLx XTkuQ6FMHWy B4uhZHtr I m2195hi9IISEHh1Asi3qv fmxFisznri4DKKw.

Click to view input data if you haven't saved it...

As you can see, the expected answer is identical with mine!

Here's my code. I think that checker might have deeme it incorrect... but why? as long as it gives the correct answer, I think it is perfectly good!

include <iostream>

using namespace std;

int bitcount(int number){ int c=0;

for(int i=0; i<8; i++){
    if(number & 1){
        c++;
    }
    number = number >> 1;
}
return c;

}

int main(int argc, const char * argv[]) { int i=0, c=0; int asciiValues[200] = {0}; char string[100] = {0};

cout << "Enter your data!" << endl;
do{
    cin >> asciiValues[i];
    c++;
    if(asciiValues[i] == 46) break;
    i++;
}while(1);

cout << "Answer: " << endl;
for(i=0; i<=c; i++){
    if(bitcount(asciiValues[i])%2 == 0){
        if(asciiValues[i] > 122) asciiValues[i] -= 128;
        string[i] = asciiValues[i];
        cout << string[i];
    }
}

cout << "\n";
return 0;

}

goto     2017-08-03 12:13:52

It might be not an issue, but your for loop have bounds "i<=c", so in the end you print null character and after that there is unnecessary new line. Both are invisible and depending on how you copy your answer, checker may complain about either of them.

Michael Gnedkovskii     2017-08-03 23:19:37

No, I usually copy my answer up to the last caracter and never copy anything after it. And that line is for my convenience only (it separates the system's message about 0 return from the rest of output).

Michael Gnedkovskii     2017-08-03 23:22:38

Hahhaha!!! Well, I tried to enter my output again right after typing the last comment and the checker accepted it....

Michael Gnedkovskii     2017-08-03 23:24:33

Anyways, I think you were right about the null character, so I reduced the bound to i<c

Please login and solve 5 problems to be able to post at forum