Awesome q2a theme
0 votes
32 views

THE PROBLEM

Code→ 

#include<iostream>
using namespace std;

int main()
{
     long int s,t,a,b,m,n; //m=number of apples, n=number of orranges
     long int ap[m], orr[n];
    cin>>s;
    cin>>t;
    cin>>a;
    cin>>b;
    cin>>m;
    cin>>n;

 long int d1= s-a;
 long int d2= t-a;

 long int q1= s-b;
 long int q2= t-b;

long int c1=0,c2=0;

    for(int i=0;i<m;i++)
    {
        cin>>ap[i];
        if(ap[i]>=d1 && ap[i]<=d2)
        {
            c1++;
        }
    }

    for(int i=0;i<n;i++)
    {
        cin>>orr[i];
        if(orr[i]<=q1 && orr[i]>=q2)
        {
            c2++;
        }
    }

cout<<c1<<"\n"<<c2;
return 0;


}

Why does it give Segmentation fault in Hacker Rank and In dev c++ the code stops by saying Windows is looking for a solution.

in Programming by (1.5k points) | 32 views
+1

I think this line

long int ap[m], orr[n];

should be after taking input of m and n

0
@Satbir why that line??
+1
since m and n are uninitialized uptil that line what will be the size of array created ?
0
@satbir..

Ya, i figured it out later...Thanks Man

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Nov 2019
  1. Satbir

    396 Points

  2. pranay562

    370 Points

  3. GAITONDE

    167 Points

  4. srestha

    96 Points

  5. Rudr Pawan

    88 Points

  6. user2525

    63 Points

  7. Pratyush Priyam Kuan

    60 Points

  8. Shaik Masthan

    53 Points

  9. Arjun

    45 Points

  10. Debapaul

    43 Points

Monthly Top User and those within 60% of his/her points will get a share of monthly revenue of GO subject to a minimum payout of Rs. 500. Current monthly budget for Top Users is Rs. 75.
1,956 questions
1,186 answers
5,550 comments
89,634 users