1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <string>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <fstream.h>
#include<fstream.h>
using namespace std;
int main() {
double x1[20]={0, 0.5 , 1 , 1.5 , 2 , 2.5 , 3 , 3.5 , 4 , 4.5 , 0 , 0.5 , 1 , 1.5 , 2 , 2.5 , 3 , 3.5,4 , 4.5 };
double y1[20]={ 0,0,0,0,0,0,0,0,0,0,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 };
double x2[20]={0.5, 1,1.5,2,2.5,3,3.5,4,4.5,5,0.5,1,1.5,2,2.5,3,3.5,4,4.5, 5};
double y2[20]={0.5, 0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1,1,1};
int number_of_data[20]={0};
stringstream ss;
string filename;
ifstream fin("alldata");
ofstream w; // declares stream variable called fout
// istringstream iss(s);
// creating 20 files data1 , data2, ........, data20
for(int i=1; i<=20;i++)
{
ss << "data" << i;
filename=ss.str();
ofstream w(filename.c_str(), ios::app);
//w << i << "\n" ;//<< LastName << "\n" << Age;
ss.str("");
cout<< filename<<endl;
}
double px1, px2, py1, py2;
int id,op;
while (fin)
{
fin >>op>> id >> px1 >> py1 >> px2 >> py2;
if (! fin.good()) continue; // skip newlines, etc.
for(int f=0; f<20; f++)
{
if ((px1>=x1[f])&&(py1>=y1[f])&&(px2<=x2[f])&&(py2<=y2[f]) )
{
number_of_data[f]++;
ss << "data" << f;
filename=ss.str();
w.open(filename.c_str(),ios::app);
w<<op<<" "<<id <<" "<<px1 <<" "<<py1 <<" "<<px2<<" "<<py2<<endl;
ss.str("");
break;
}//end if
}//end for
return 0;
}
}
|