samedi 28 février 2015

runtime error using sort function in C++

i have been solving a problem called Sort! Sort!! And Sort!!! on uva but the problem is that my code get runtime error whenever i submit it and i don't know why , i wonder if there is anyone who could help me



int m;
bool condition(int first , int second)
{
if(first%m<second%m){return first>second;}
if(first%m>second%m){return first<second;}
else
{
if(first%2!=0 && second%2==0){return first>second;}
if(first%2==0 && second%2!=0){return first<second;}
if(first%2!=0 && second%2!=0)
{
if(first>second){return first>second;}
if(second>first){return first<second;}
if(second==first){return 0 ;}
}
if(first%2==0 && second%2==0)
{
if(first>second){return first<second;}
if(second>first){return first>second;}
if(second==first){return 0;}
}
}
return 0;
}

int main()
{
int n,x;
while(cin>>n>>m)
{
if(n==0 && m==0){cout<<n<<" "<<m<<endl; break;}
vector <int> vec;
for(int j=0;j<n;j++)
{
cin>>x;
vec.push_back(x);
}
sort(vec.begin(),vec.end(),condition);
cout<<n<<" "<<m<<endl;
for(int j=0;j<n;j++)
{
cout<<vec[j]<<endl;
}
vec.clear();
}
return 0;
}

Aucun commentaire:

Enregistrer un commentaire