Блог пользователя nithilanm

Автор nithilanm, история, 2 месяца назад, По-английски

514A - Чубакка и число 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

  • Проголосовать: нравится
  • -1
  • Проголосовать: не нравится

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

  • »
    »
    2 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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!

    • »
      »
      »
      2 месяца назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        2 месяца назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        2 месяца назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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.

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.