1 / 4
Jan 2011

i was solving problem MEOWIST
i dont the reason why i keep getting runtime error sisgev in this kind of problem

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
using namespace std;
int main()
{
    string s;
    int a[500];
    for(int i=0;i<500;i++)
    {
            a[i]=-1;
    }
    vector<string> v;
    vector<string>::iterator it;
    int k=0;
    while(cin>>s)
    {
         int age,i,check=0;
         cin>>age;
       for(i=k-1;i>=0;i--)
         {
                 if(a[i]<age)
                 {
                       a[i+1]=age;
                       k++;
                       break;
                 }
                 if(a[i]==age)
                 {
                                 check=1;
                                 k++;
                                 break;
                 }
                 else
                 {
                     a[i+1]=a[i];
                 }
         }         
         if(i==-1)
         {
                  a[0]=age;
                  k++;
         }
         if(check==1)
         {
                     string s1=v[i];
                     if(s1>s)
                     {
                             i=i;
                     }
                     else{
                          i=i-1;
                     }
         }
         it=v.begin()+i+1;
    //     cout<<"to inseert at  "<<i<<endl;
         v.insert(it,1,s);
    }
    for(int i=k-1;i>=0;i--)
    {
            cout<<v[i]<<endl;
    }
    return 0;
}
  • created

    Jan '11
  • last reply

    Jan '11
  • 3

    replies

  • 113

    views

  • 2

    users

no information is given regarding about number of name in input file ...so to be safe i took 500.
i even tired it with 100 but got same result(runtime error)

I'd be more worried that it isn't enough. If a constraint isn't listed then that should be a clue that you need to use a method that isn't dependent on that size.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 13 5d

Want to read more? Browse other topics in C and C++ or view latest topics.