Блог пользователя AL-Yassin-105

Автор AL-Yassin-105, история, 20 месяцев назад, По-английски

at the last "Div 2" round i sent solution for problem B but i get Wrong answer on test 2 ....I spend a lot of time try to discover why my idea is wrong?!! actually my idea and my code was true , but because (sqrt function do not work in GNU 20 with long long number and same function work with GNU 17 i get wrong answer and my rate will decrase more than 150 point,** so please if you know some issues like this, please type it in the comment to know it , especially in differences between these two compilers**

my code AC on GNU 17 , WA on GNU 20

https://codeforces.net/contest/1809/submission/198835668

https://codeforces.net/contest/1809/submission/198811956

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

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

Auto comment: topic has been updated by AL-Yassin-105 (previous revision, new revision, compare).

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

You could've evaded it using sqrtl as 198837320 or implementing sqrt using binary search.

However, this issue is old. There is a separate blog I wrote abt before.

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

    thanks , and i want to know if there are more differences , there was another issue in another problem in that time i do not know what the difference between them

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

Never mind bro, you can rise again next contest , just never give up :)

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

You can't write a struct name as data and pass it as a parameter of a function. It will run in C++14 but give errors in C++17 and C++20.

Here is an example code:

#include <iostream>
using namespace std;

struct data{
    int a,b;
};

int sum(data f){
    return f.a+f.b;
}
int main()
{
    struct data x;
    x.a=1;
    x.b=2;
    cout<<sum(x)<<endl;
    return 0;
}

It will run in C++14. But give errors in C++17 and C++20.

I faced this problem in the ICPC2022 preliminary round to solve the problem of Proximity Card Data Statistics. I used the struct name as data and pass it into a function, as a result, I was getting a Compilation error in the contest. But my code was smoothly running on my local pc. As a result, I lose 45 minutes of figuring out the problem.

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

    do you mean data is a key word ?! in c++17 and c++20 !?

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

      No, data isn't a keyword. You can use it as a variable. i.e

      #include <iostream>
      using namespace std;
      
      
      int main()
      {
          int data =5;
          cout<<data<<endl;
          return 0;
      }
      

      You can run it in C++14, C++17, C++20, etc. But when you use data as a struct name and pass it to a function as the parameter (I mention it in a previous comment) then it won't work in C++17 and C++20 (As I tested it in C++14, C++17, and C++20).

      And it is happening because, In C++14, it is allowed to omit the struct/union/class keyword when referring to a member of a struct/union/class, as long as the intended member is not a type name. This is called "implicit conversion from class to its first data member" and is a language feature. However, in C++17 and C++20, this feature was removed due to inconsistency in the language and potential conflicting interpretations by different compilers. As a result, using a struct name as data and passing it as a parameter of a function is no longer allowed in these newer versions of C++.

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

    You can't use data because it is declared in C++ std namespace. However, if you change function sum to

    int sum(::data f){
        return f.a+f.b;
    }
    

    It will be compiled without any problems

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

it's your mistake not anyone else you should know every thing about the function you use in your code