summaryrefslogtreecommitdiff
path: root/planet.cc
blob: 33cdea7c0fbd20c1c8fadb01d49c9ea454348a77 (plain)
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
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

int main()
{
	ifstream in;
	ofstream out;
	in.open("input.txt");
	out.open("output.txt");
	
	char ch;
	string numero, val[2];
	int oraVuota = -1, giorno[96], i = 0, c = 0;
	
	for(int j = 0; j < 96; j++) giorno[j] = -1;
	
	getline(in, numero);
	int N;
	istringstream(numero) >> N;
	
	int ore[N][2];
	
	while(!in.eof())
	{
		in.get(ch);
		
		if(ch == '\n') {
			val[0] = "";
			val[1] = "";
			i = 0;
			c++;
			
			continue;
		}else if(ch == ' '){
			i++;
		}else {
			val[i] += ch;
			istringstream(val[i]) >> ore[c][i];
		}
		
	}
	
	i = 0;
	while(i < N){
		if(ore[i][0] > ore[i][1]){
			for(int j = ore[i][0]; j < ore[i][1] || j < 96; j++) giorno[j] = 0;
			for(int k = ore[i][1]-1; k >= 0; k--) giorno[k] = 0;
		}else {
			for(int k = ore[i][0]; k < ore[i][1]; k++) giorno[k] = 0;
		}
		i++;
	}
	
	for(i = 0; i < 96; i++) {
		if(giorno[i] == -1) {
			oraVuota = i;
			break;
		}
		
		//cout << i << " " << giorno[i] << endl;
	}
	
	out << oraVuota << endl;
		
	in.close();
	out.close();
	
	return 0;
}