c++ - How to split a full=number into two groups according to their position(even or odd) -


this question has answer here:

my input

 4  1 2  3 4  5 6  7 8 

what want split 2 groups. how split full=number 2 groups according position(even or odd) asked here.ithought answer correct.when check boy[3]; there seems problem.here code,i cannot find mistake?what should out 8

#include<fstream> #include<iostream> using namespace std;  int main(){ ifstream ifs("q3_in.txt");  int g; ifs>>g; int boy[g];int girl[g]; int =0; int b = 0;  for(int i=0;i<g;i++){  if(i%2) ifs>>boy[b++];  else ifs>>girl[a++];  }  cout<<boy[3];  system("pause");  return 0;} 

i < g*2 solution. input size 2*g not g.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -