Hello , I have tried several ideas , times and ways to do this but all fail on the site's test , could any1 give me an idea or something
Problem

#include <iostream>

using namespace std;
long int q,n,i,point,casenr;
long int marbles[10000];
int main (){

    while(1==1){

          cin>>n>>q;casenr++;

          if(n==0 && q==0)break;
          if(casenr!=1)cout<<endl;
          cout<<"CASE# "<<casenr<<":";

          for(i=1;i<=n;i++){
              cin>>point;
              if(marbles[point]==0)
                 marbles[point]=i;

              }
          for(i=1;i<=q;i++){
              cin>>point;

              if(marbles[point]!=0)
                 cout<<endl<<point<<" found at "<<marbles[point]+1;

              if(marbles[point]==0)
                 cout<<endl<<point<<" not found";

          }

              /////While Ended
          }
///////End The Program
system("Pause");
}

Edited 6 Years Ago by Robert1995: A good title

The way I understand the problem, the array does not have to have 10000 elements -- 10000 is just the maximum value that any one element may contain. In otherwords you have to generate an array that contains N elements (allocate with new operator), the value of each element is randomly selected between 0 and 10000.

After you find out the value of N, allocate an array of N integers then populate it with values between 0 and 10000. You can use array[i] = rand() % 10000; in a loop.

After that, you need another loop from 0 to Q. In that loop you need to generate another random number between 0 and 10000 then try to find that number in the array.

Of course, I could be all wrong about the problem too :)

Edited 6 Years Ago by Ancient Dragon: n/a

The way I understand the problem, the array does not have to have 10000 elements -- 10000 is just the maximum value that any one element may contain. In otherwords you have to generate an array that contains N elements (allocate with new operator), the value of each element is randomly selected between 0 and 10000.

After you find out the value of N, allocate an array of N integers then populate it with values between 0 and 10000. You can use array[i] = rand() % 10000; in a loop.

After that, you need another loop from 0 to Q. In that loop you need to generate another random number between 0 and 10000 then try to find that number in the array.

Of course, I could be all wrong about the problem too :)

I got it :)! similar to your idea , i got it all wrong in a place thanks :)

Edited 6 Years Ago by Robert1995: n/a

This question has already been answered. Start a new discussion instead.