-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (44 loc) · 1.09 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
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
FILE *in = stdin;//fopen("input.txt","r");
int startDay, endDay, price;
int *priceTable = new int[50000];
while(fscanf(in, "%d %d %d", &startDay, &endDay, &price) == 3)
{
for(int i = startDay; i <= endDay && i < 50000; i++)
priceTable[i] = price;
}
int index = 0;
bool isFirst = true;
while(index < 50000)
{
price = 0;
while(index < 50000 && priceTable[index] == 0)
index++;
startDay = index;
price = priceTable[index];
while(index < 50000 && priceTable[index] == price)
index++;
endDay = index-1;
if(isFirst)
{
printf("[%d, %d, %d]", startDay, endDay, price);
isFirst = false;
}else if(price != 0)
{
printf(",[%d, %d, %d]", startDay, endDay, price);
}
}
delete[] priceTable;
return 0;
}