-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ1-Countdown.cpp
60 lines (56 loc) · 1.31 KB
/
Q1-Countdown.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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define maxN 200000+50
// 直接遍历+判断即可
int main()
{
int num[maxN];
int t,T,N,n,K,k,temp_K;
int cnt,flag;
scanf("%d", &T);
for(t=1; t<=T; t++)
{
cnt = 0;
memset(num, 0, sizeof(num));
scanf("%d %d", &N, &K);
// 先全部输入
for(n=0; n<N; n++)
{
scanf("%d", &num[n]);
}
for(n=0; n<N; n++)
{
// 发现K值,判断是否为m-countdown
if(num[n] == K)
{
flag = 1;
temp_K = K;
// 向后遍历K个数
for(k=0; k<K; k++)
{
if(num[n+k] == temp_K)
{
temp_K = temp_K-1;
continue;
}
else
{
flag = 0;
break;
}
}
if(flag == 1)
{
cnt++;
//n = n+K;
}
}
}
printf("Case #%d: %d\n", t, cnt);
}
/* std::cout << "Hello world" << std::endl; */
return 0;
}