Hello!
So basically my task is to make a program that handles measurements of the water height at different points of a river.
Basically where the height is under 800 cm there is no alert,under 900 cm there is a first-degree alert,under 1000 cm second-degree alert and over 1000 cm third-degree alert.
The beggining of the programs works fine,where I needed to search how many floodings are between the measurements and give its starting and ending points.
The beggining of the second part works fine as well where my job was to search how many sudden floodings happened meaning from where there was no alert the next measure point had a third-degree alert. And now I would have to give those points starting and ending points.
I am a pretty big beginner and worked like 2 days with this code, while the second day was almost only trying to figure out whats my mistake at the end but I just cant get it right.
Some verbs that you probably wont understand since its in my own language:
meres=Measurement
kezdet=beginning
veg=end
hirtkezd=sudden beggining
hirtveg=sudden end
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
|
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int meres[n];
for (int i=0; i<n; ++i)
{
cin >> meres[i];
}
int k=0;
for (int i=0; i<n; ++i)
{
if(i==0)
{
if(meres[0] > 800)
++k;
}
else
{
if(meres[i] > 800 & meres[i-1] <= 800)
++k;
}
}
int kezdet[k];
int veg[k];
int a=0;
int b=0;
if(k!=0)
{
for(int i=0; i<n; ++i)
{
if(i==0)
{
if(meres[0] > 800)
{
kezdet[a]=i+1;
++a;
}
}
else
{
if((meres[i] > 800) & (meres[i-1] <= 800))
{
kezdet[a]=i+1;
++a;
}
else
{
if((meres[i] <= 800) & (meres[i-1] > 800))
{
veg[b]=i;
++b;
}
}
}
if((i==n-1) & (meres[i] > 800))
veg[b]=i+1;
}
}
int m=0;
for(int i=0; i<n; ++i)
{
if((i==0) & (meres[i] > 1000))
++m;
if(i!=n-1)
{
if((meres[i] <= 800) & (meres[i+1] > 1000))
++m;
}
}
int hirtkezd[m];
int hirtveg[m];
int c=0;
int d=0;
int e=0;
if(m!=0)
{
for(int i=0; i<n; ++i)
{
if(i!=n-1)
{
if((meres[i] < 800) & (meres[i+1] > 1000))
{
hirtkezd[c]=i+1;
++c;
e=i+1;
while(meres[e] > 1000)
{
++e;
}
hirtveg[d] = e+1;
++d;
}
}
}
}
cout << k << endl;
for (int i=0;i<k;++i)
{
cout << kezdet[i] << " " << veg[i] << " ";
}
cout << endl;
cout << m << endl;
for (int i=0;i<m;++i)
{
cout << hirtkezd[i] << " " << hirtveg[i] << " ";
}
return 0;
}
|