include stdio include math include stdlib enum A_R_Krym Vinnytska Voly

  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
enum {A_R_Krym=0,Vinnytska=1,Volynska,Dnipropetrovska,Donetska,Zhytomyrska,Zakarpatska,Zaporizka,Ivano_Frankivska,Kirovogradska,Kyivska,Lvivska,Luganska,Mykolayivska,Odeska,Poltavska,Rivnenska,Sumska,Ternopilska,Kharkivska,Khersonska,Khmelnitska,Cherkaska,Chernivetska,Chernigivska} Ukraine;
const char* region_name[25]={"A_R_Krym","Vinnytska","Volynska","Dnipropetrovska","Donetska","Zhytomyrska","Zakarpatska","Zaporizka","Ivano_Frankivska","Kirovogradska","Kyivska","Lvivska","Luganska","Mykolayivska","Odeska","Poltavska","Rivnenska","Sumska","Ternopilska","Kharkivska","Khersonska","Khmelnitska","Cherkaska","Chernivetska","Chernigivska"};
int main(int argc, char *argv[])
{if (argc>=3)
{double eps;
if (argc==4)
{eps=atof(argv[3]);}
else eps=0.0000001;
char* zagolovok;
zagolovok= new char[140];
double lat,lon,regions[25][13],d[12];
FILE *f,*out;
f=fopen(argv[1],"r");
out=fopen(argv[2],"w");
for(int i=A_R_Krym;i<=Chernigivska;i++)
for(int j=0;j<13;j++)
regions[i][j]=0.0;
fgets(zagolovok,140,f);
while(!feof(f))
{fscanf(f,"%lf %lf",&lat,&lon);
for(int i=0;i<12;i++)
fscanf(f," %lf",&d[i]);
if ((fabs(lat-45.52485)<=eps)&&((fabs(lon-33.75)<=eps)||(fabs(lon-35.15625)<=eps)||(fabs(lon-36.5625)<=eps)))
{for(int i=0;i<12;i++)
regions[A_R_Krym][i]+=d[i];
regions[A_R_Krym][12]+=1.0;
}
if ((fabs(lat-48.326363)<=eps)&&((fabs(lon-33.75)<=eps)||(fabs(lon-35.15625)<=eps)||(fabs(lon-36.5625)<=eps)))
{for(int i=0;i<12;i++)
regions[Dnipropetrovska][i]+=d[i];
regions[Dnipropetrovska][12]+=1.0;
}
if (((fabs(lat-49.727116)<=eps)&&((fabs(lon-29.53125)<=eps)||(fabs(lon-30.9375)<=eps)))||((fabs(lat-51.127865)<=eps)&&(fabs(lon-29.53125)<=eps)))
{
for(int i=0;i<12;i++)
regions[Kyivska][i]+=d[i];
regions[Kyivska][12]+=1.0;
}
if (((fabs(lat-48.326363)<=eps)&&((fabs(lon-28.125)<=eps)||(fabs(lon-29.53125)<=eps)))||((fabs(lat-49.727116)<=eps)&&(fabs(lon-28.125)<=eps)))
{
for(int i=0;i<12;i++)
regions[Vinnytska][i]+=d[i];
regions[Vinnytska][12]+=1.0;
}
if ((fabs(lat-51.127865)<=eps)&&((fabs(lon-30.9375)<=eps)||(fabs(lon-32.34375)<=eps)))
{
for(int i=0;i<12;i++)
regions[Chernigivska][i]+=d[i];
regions[Chernigivska][12]+=1.0;
}
if ((fabs(lat-49.727116)<=eps)&&((fabs(lon-36.5625)<=eps)||(fabs(lon-37.96875)<=eps)))
{
for(int i=0;i<12;i++)
regions[Kharkivska][i]+=d[i];
regions[Kharkivska][12]+=1.0;
}
if ((fabs(lat-48.326363)<=eps)&&((fabs(lon-30.9375)<=eps)||(fabs(lon-32.34375)<=eps)))
{
for(int i=0;i<12;i++)
regions[Kirovogradska][i]+=d[i];
regions[Kirovogradska][12]+=1.0;
}
if ((fabs(lon-39.375)<=eps)&&((fabs(lat-48.326363)<=eps)||(fabs(lat-49.727116)<=eps)))
{
for(int i=0;i<12;i++)
regions[Luganska][i]+=d[i];
regions[Luganska][12]+=1.0;
}
if (((fabs(lat-45.52485)<=eps)&&(fabs(lon-29.53125)<=eps))||((fabs(lat-46.925606)<=eps)&&(fabs(lon-30.9375)<=eps)))
{
for(int i=0;i<12;i++)
regions[Odeska][i]+=d[i];
regions[Odeska][12]+=1.0;
}
if ((fabs(lat-49.727116)<=eps)&&((fabs(lon-33.75)<=eps)||(fabs(lon-35.15625)<=eps)))
{
for(int i=0;i<12;i++)
regions[Poltavska][i]+=d[i];
regions[Poltavska][12]+=1.0;
}
if ((fabs(lat-51.127865)<=eps)&&((fabs(lon-33.75)<=eps)||(fabs(lon-35.15625)<=eps)))
{
for(int i=0;i<12;i++)
regions[Sumska][i]+=d[i];
regions[Sumska][12]+=1.0;
}
if ((fabs(lat-51.127865)<=eps)&&((fabs(lon-23.90625)<=eps)||(fabs(lon-25.3125)<=eps)))
{
for(int i=0;i<12;i++)
regions[Volynska][i]+=d[i];
regions[Volynska][12]+=1.0;
}
if ((fabs(lat-48.326363)<=eps)&&((fabs(lon-25.3125)<=eps)||(fabs(lon-26.71875)<=eps)))
{
for(int i=0;i<12;i++)
regions[Chernivetska][i]+=d[i];
regions[Chernivetska][12]+=1.0;
}
if ((fabs(lat-48.326363)<=eps)&&((fabs(lon-22.5)<=eps)||(fabs(lon-23.90625)<=eps)))
{
for(int i=0;i<12;i++)
regions[Zakarpatska][i]+=d[i];
regions[Zakarpatska][12]+=1.0;
}
if ((fabs(lat-46.925606)<=eps)&&((fabs(lon-35.15625)<=eps)||(fabs(lon-36.5625)<=eps)))
{
for(int i=0;i<12;i++)
regions[Zaporizka][i]+=d[i];
regions[Zaporizka][12]+=1.0;
}
if ((fabs(lat-49.727116)<=eps)&&(fabs(lon-32.34375)<=eps))
{
for(int i=0;i<12;i++)
regions[Cherkaska][i]+=d[i];
regions[Cherkaska][12]+=1.0;
}
if ((fabs(lat-48.326363)<=eps)&&(fabs(lon-37.96875)<=eps))
{
for(int i=0;i<12;i++)
regions[Donetska][i]+=d[i];
regions[Donetska][12]+=1.0;
}
if ((fabs(lat-48.326363)<=eps)&&(fabs(lon-26.71875)<=eps))
{
for(int i=0;i<12;i++)
regions[Ivano_Frankivska][i]+=d[i];
regions[Ivano_Frankivska][12]+=1.0;
}
if ((fabs(lat-46.925606)<=eps)&&(fabs(lon-33.75)<=eps))
{
for(int i=0;i<12;i++)
regions[Khersonska][i]+=d[i];
regions[Khersonska][12]+=1.0;
}
if ((fabs(lat-49.727116)<=eps)&&(fabs(lon-26.71875)<=eps))
{
for(int i=0;i<12;i++)
regions[Khmelnitska][i]+=d[i];
regions[Khmelnitska][12]+=1.0;
}
if ((fabs(lat-49.727116)<=eps)&&(fabs(lon-23.90625)<=eps))
{
for(int i=0;i<12;i++)
regions[Lvivska][i]+=d[i];
regions[Lvivska][12]+=1.0;
}
if ((fabs(lat-46.925606)<=eps)&&(fabs(lon-32.34375)<=eps))
{
for(int i=0;i<12;i++)
regions[Mykolayivska][i]+=d[i];
regions[Mykolayivska][12]+=1.0;
}
if ((fabs(lat-51.127865)<=eps)&&(fabs(lon-26.71875)<=eps))
{
for(int i=0;i<12;i++)
regions[Rivnenska][i]+=d[i];
regions[Rivnenska][12]+=1.0;
}
if ((fabs(lat-49.727116)<=eps)&&(fabs(lon-25.3125)<=eps))
{
for(int i=0;i<12;i++)
regions[Ternopilska][i]+=d[i];
regions[Ternopilska][12]+=1.0;
}
if ((fabs(lat-51.127865)<=eps)&&(fabs(lon-28.125)<=eps))
{
for(int i=0;i<12;i++)
regions[Zhytomyrska][i]+=d[i];
regions[Zhytomyrska][12]+=1.0;
}
}
for(int i=0;i<8;zagolovok[i]=' ',i++);
fputs(" ",out);
fputs(zagolovok,out);
for(int i=A_R_Krym;i<=Chernigivska;i++)
{fprintf(out,"\n%16s: ",region_name[i]);
for(int j=0;j<12;j++)
fprintf(out,"%10lf ",regions[i][j]/regions[i][12]);
}
delete(zagolovok);
fclose(f);
fclose(out);
}
else printf("Wrong parameters.\nUse \"vyborka.exe source_file result_file [epsilon]\"\n");
return 0;
}