c++ - Vector declaration globally and in the main class -


i writing code , in when declare vector globally , gives wrong answer when declare in main function . becomes right . want know difference between 2 declarations

this code find min of first enteries, , 2nd min of 2nd enteries , if min >= 2nd min print no . here declared vector in main class when declare ints declared , site on submitting gives me wrong answer.

#include<iostream> #include<algorithm> #include<vector> #include<cstdio>  using namespace std;  #define max 20000; int a,b,c,d,i,z;   int main() {         scanf("%d %d", &a, &b);         while( a!=0 && b!=0)         {             z = max;             for(i=0;i<a;i++)             {                 scanf("%d",&c);                 if(z>c)                 {                     z=c;                 }             }               vector<int> v;               for(i=0;i<b;i++)             {                 scanf("%d",&d);                 v.push_back(d);             }             sort(v.begin(),v.end());              if (z >= v[1])             printf("n\n");             else             printf("y\n");         scanf("%d %d", &a, &b);         }            return 0; } 

sudhanshu

if declare vector global variable, should invoke vector::clear() in begin of loop clear of elements stored in last loop.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -