Codeforces compilation error

Codeforces. Programming competitions and contests, programming community

8 years ago,
#
|



Rev. 3


 


Vote: I like it
+8
Vote: I do not like it

You are using the to_string method to convert an integer to a string. This function only exists in C++11 and doesn’t exist in previous versions. However, you are submitting in GNU C++, not C++ 11. A solution is to change the programming language you are submitting into GNU C++0x.

8 years ago,
#
|


Vote: I like it
0
Vote: I do not like it

In Codeforces, you can submit your code in Custom Invocation to view the error information outputted by compiler when you got «strange» Compilation Error.

2 years ago,
#
|


Vote: I like it
+11
Vote: I do not like it

Check your header file sometimes our computer compiler run our code without including the header file(like we can use string related function without using string.h header file) but an online judge can’t run a code properly without including the header file. So, check the header file :-).

  • 2 years ago,
    #
    ^
    |


    Vote: I like it
    +20
    Vote: I do not like it

    thanks for replying after 6 years :)

    • 2 years ago,
      #
      ^
      |


      Vote: I like it
      +8
      Vote: I do not like it

      Am still looking at comments though after 6 years haha

      • 21 month(s) ago,
        #
        ^
        |


        Vote: I like it
        0
        Vote: I do not like it

        When u are submitting try to see which programming language is set.

        • 21 month(s) ago,
          #
          ^
          |


          Vote: I like it
          0
          Vote: I do not like it

          The it liked MS C++, but I wanted to stick with GNU C++, so I refactored my code. I still got wrong answers afterward, but finally got an accepted answer at Submission #8759965 — Codeforces

          • 4 months ago,
            #
            ^
            |


            Vote: I like it
            0
            Vote: I do not like it

            Did you get to solve the previous problem I ised -‘0’and it is giving compiler error

can anyone help me in this

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long int
struct points{
ll a;
ll b;
};
int cos(points x , points y)
{
    return x.b<y.b;
}
int main()
{
   ll n,r,avg,i,j,k;
   points pt[100005];
   cin>>n>>r>>avg;
   for(i=0;i<n;i++)
   {
       cin>>pt[i].a>>pt[i].b;
   }
   sort(pt,pt+n,cos);
   ll sum=avg*n;
   for(i=0;i<n;i++)sum-=pt[i].a;
   if(sum<=0)cout<<"0n";
   else
   {

   ll ans=0;
   for(i=0;i<n;i++)
   {
       if(sum==0)break;
       else
       {
           if(sum>r-pt[i].a)
           {
               ans=ans+pt[i].b*(r-pt[i].a);
               sum=sum-(r-pt[i].a);
           }
           else
           {
               ans=ans+sum*pt[i].b;
               sum-=sum;
           }
       }
   }
   cout<<ans<<endl;
   }
    return 0;
}

when im compiling in my system its working fine and getting the correct output but when i’m submitting in codeforces under GNUC++ 11 im getting compllation error? can u help me

timrau's user avatar

timrau

22.4k4 gold badges52 silver badges64 bronze badges

asked May 30, 2015 at 17:40

rap's user avatar

4

Your compare function, cos(), collides with function in standard <cmath>. Rename it and it will compile.

answered May 30, 2015 at 17:49

timrau's user avatar

timrautimrau

22.4k4 gold badges52 silver badges64 bronze badges

0

A and B are preparing themselves for programming contests.

B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.

Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.

However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.

Can you help B find out exactly what two errors he corrected?

Input

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.

The second line contains n space-separated integers a1, a2, …, an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.

The third line contains n - 1 space-separated integers b1, b2, …, bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.

The fourth line contains n - 2 space-separated integers с1, с2, …, сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Output

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

Sample test(s)

Input

5
1 5 8 123 7
123 7 5 1
5 1 7

Input

6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5

Note

In the first test sample B first corrects the error number 8, then the error number 123.

In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

This topic is actually done last week. Today, I just encountered it, I wrote it.

When you write on Sunday, use sort, scanning methods, easy to think. This approach is JS, gives each set, and a set of and a set of sums is the answer.


 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int n, read;
10     int sum1, sum2, sum3;
11     sum1 = sum2 = sum3 = 0;
12     scanf("%d", &n);
13     for(int i = 0; i < n; i++)
14     {
15         scanf("%d", &read);
16         sum1 += read;
17     }
18 
19     for(int i = 0; i < n-1; i++)
20     {
21         scanf("%d", &read);
22         sum2 += read;
23     }
24     cout << sum1 - sum2 << endl;
25 
26     for(int i = 0; i < n-2; i++)
27     {
28         scanf("%d", &read);
29         sum3 += read;
30     }
31 
32     cout << sum2 - sum3 << endl;
33     return 0;
34 }

View Code

519B Codeforces

A and B and compilation Errors

Solution in c++

#include <vector>

#include <algorithm>

#include <cstdio>

using namespace std;

int main()

{

    long e,t;

    scanf(«%ld»,&e);

    vector<long> initial(e),first(e-1),second(e-2),out(1);

    for(long i=0;i<initial.size();i++)scanf(«%ld», &initial[i]);

    for(long i=0;i<first.size();i++)scanf(«%ld»,&first[i]);

    for(long i=0;i<second.size();i++)scanf(«%ld»,&second[i]);

    sort(initial.begin(), initial.end());

    sort(first.begin(), first.end());

    sort(second.begin(), second.end());

    std::set_difference(initial.begin(), initial.end(), first.begin(), first.end(), out.begin());

    std::set_difference(first.begin(), first.end(), second.begin(), second.end(), &out[1]);

    printf(«%ld n%ldn», out[0], out[1]);

    return 0;

}

About
Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.

Следующий код работает нормально, пока я использую его в своем приложении блоков кода. Однако при решении проблемы «Четные шансы» в Codeforces путем отправки того же кода я получаю ошибку компиляции.

Ошибка: недопустимое преобразование из ‘void *’ в ‘long long int *’ [-fpermissive]

Я новичок в программировании на C. Итак, пожалуйста, помогите мне, как я могу исправить этот мой код.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
long long *arr, n, k, i, n1, n2, m;
scanf("%I64d%I64d", &n, &k);
arr=malloc(sizeof(long long)*n);
    n1=1;n2=2;
for(i=0;i<=n/2&&n1<=n;i++){
    arr[i]=n1;
    n1+=2;
    }
if(n%2!=0) m=n/2+1;
else m=n/2;
for(i=m;i<=n&&n2<=n;i++){
    arr[i]=n2;
    n2+=2;
    }
printf("%I64d", arr[k-1]);
free(arr);

return 0;
}

1 ответ

Лучший ответ

В кодовых блоках вы должны компилировать его как файл c. Но в Codeforces код компилируется как cpp.

arr=malloc(sizeof(long long)*n);

Когда вы компилируете эту строку на C, malloc выдаст указатель void*, который будет автоматически преобразован в long long*

Но в случае cpp явное преобразование должно выполняться. Чтобы запустить код в cpp:

arr = (long long*)malloc(sizeof(long long) * n);

Это сработает. Прочтите эту статью для получения разъяснений.


1

Ardent Coder
22 Фев 2020 в 16:55

Понравилась статья? Поделить с друзьями:
  • Codeblocks fatal error iostream no such file or directory
  • Codeblocks environment error что делать
  • Codebase error unrecognized field name
  • Codebase error 70 reading file
  • Codebase error 630 optimization file flushing failure