-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsi2.cpp
More file actions
57 lines (46 loc) · 1.48 KB
/
Copy pathcsi2.cpp
File metadata and controls
57 lines (46 loc) · 1.48 KB
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
#include <utility>
using namespace std;
int main(){
map< pair<int,float> , int > data; map< pair<int,float> , int >::iterator it;
map< pair<int,float> , int > map2;
pair<int,float> idTempPair;
//int countOfLines=0;
int id;
int timestamp;
float temp;
char comma;
ifstream myfile("input.txt");
string line;
while (std::getline(myfile, line))
{
istringstream tokenizer(line);
if (!(tokenizer >> id >> comma >> timestamp >> comma >> temp)) { continue; }
if(timestamp>=0 && timestamp<=59 && temp<=(float)100.00 && temp>=(float)0.00){
//countOfLines++;
idTempPair = make_pair(id, temp);
data[idTempPair] = data[idTempPair] + 1;
map2[idTempPair] = timestamp;
}
}
myfile.close();
ofstream outFile("output.txt");
for(it = data.begin(); it!=data.end(); it++){
if(it == data.begin())
if(it->second == 1)
outFile<<it->first.first<<", "<<map2[it->first]<<", "<<it->first.second;
else
outFile<<it->first.first<<", "<<"0, "<<it->first.second<<", "<<it->second;
else
if(it->second == 1)
outFile<<'\n'<<it->first.first<<", "<<map2[it->first]<<", "<<it->first.second;
else
outFile<<'\n'<<it->first.first<<", "<<"0, "<<it->first.second<<", "<<it->second;
}
outFile.close();
return 0;
}