nithilanm's blog

By nithilanm, history, 5 weeks ago, In English

514A - Chewbaсca and Number Hello! I am relatively new to CF and CP overall, but I was wondering if someone more experienced can look at this problem and check whether my solution to this test case is incorrect or if there is an issue with the test solution. As you can see, I got the least possible positive number with the problem conditions but the test is saying I am incorrect.

 Test Case

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by nithilanm (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Yeah,the problem statement is a bit unclear and I too faced this issue. Maybe the crux is that it says "The decimal representation shouldn't start with 0" So,I changed the condition that if the first digit is 9 then don't change it, otherwise make it min(t,9-t) and then it got accepted.

  • »
    »
    5 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    My solution was to invert all nums less than or equal to '5', and if the final output was '0' i'd invert it and output "9" instead. This solution is the optimal one in theory, but we need to fit the testcases ig. Alright, thank you!

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It said you cannot make the first digit 0 ..in meant you cannot change the number of digits...

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes, exactly. I too was wondering after 5 WA what was up then read it again to find out

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        They never said you can't make the first digit zero. They said no leading zeros in the final decimal representation of the number. So if you have 900, you can make it 009 and then remove the leading zeros for the final representation. I understand the confusion here, but I do believe my code answers the question posed and not the one intended by the problem creators.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

int main() {

string s;
cin >> s;
string ans ;
for (int i = 0; i < s.size(); i ++){
    char cur = s[i];
    int digit = cur - '0'; 

    if (digit > 4) {
        digit = 9 - digit;
        if (i== 0 and digit == 0){
            digit = 9;
        }
    }

    ans += to_string(digit);
}

cout << ans; return 0;

}

basically if digit > 4, we transform it. sole exception being that if i == 0 and digit == 9, in this case we skip the transformation, as asked in the question.