-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
99 lines (95 loc) · 2.37 KB
/
main.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<string>
#include<fstream>
#include<bits/stdc++.h>
using namespace std;
string fun(string s)
{
if(!s.compare("Fog"))
return "0100";
if(!s.compare("Rain"))
return "0010";
if(!s.compare("Thunderstorm"))
return "0001";
return "1000";
}
int main()
{
fstream fin,fout;
int i=1;
bool arr[25]={false};
arr[1]=true;
arr[3]=true;
arr[4]=true;
arr[6]=true;
arr[7]=true;
arr[9]=true;
arr[10]=true;
arr[12]=true;
arr[13]=true;
arr[15]=true;
arr[16]=true;
arr[19]=true;
arr[21]=true;
char buffer[33];
for(i=1;i<=6;i++)
{
itoa(i,buffer,10);
string a(buffer);
string s="200"+a+".txt";
fin.open(s.c_str(),ios::in);
s="Weather"+s;
fout.open(s.c_str(),ios::out);
string line;
while(!fin.eof())
{
getline(fin,line);
int count=0;
fout<<"1 ";
for(int i=0;i<line.size();i++)
{
string word="";
while(i<line.size()&&line[i]!=',')
{
word+=line[i];
i++;
}
if(!arr[count])
{
count++;
continue;
}
if(count==21)
{
std::size_t found = word.find("-");
if(word.size()==0)
fout<<"1000";
else if (found!=std::string::npos)
{
string newword="";
int j=word.size()-1;
while(j>-1&&word[j]!='-')
{
newword=word[j]+newword;
j--;
}
fout<<fun(newword);
}
else
{
fout<<fun(word);
}
fout<<" ";
}
else if(arr[count])
{
fout<<word<<" ";
}
count++;
}
fout<<endl;
}
fin.close();
fout.close();
}
return 0;
}