-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPman.cpp
More file actions
48 lines (41 loc) · 1.16 KB
/
IPman.cpp
File metadata and controls
48 lines (41 loc) · 1.16 KB
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
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
int main() {
int t;
scanf("%d", &t);
getchar();
char input[105];
for (int k = 0; k < t; k++) {
scanf("%s", input); getchar();
bool isValid = true;
int length = strlen(input);
// Persyaratan pertama: Setiap angka harus mengapit satu '.'
for (int i = 0; i < length; i++) {
if (input[i] == '.') {
if (i == 0 || i == length - 1 || input[i - 1] == '.' || input[i + 1] == '.') {
isValid = false;
break;
}
}
}
// Persyaratan kedua: Setiap string tidak boleh diawali atau diakhiri dengan '.'
if (input[0] == '.' || input[length - 1] == '.') {
isValid = false;
}
// Persyaratan tambahan: Setiap angka harus mengapit satu '.'
for (int i = 1; i < length - 1; i++) {
if (input[i] != '.' && input[i - 1] != '.' && input[i + 1] != '.') {
isValid = false;
break;
}
}
printf("Case #%d: ", k+1);
if (isValid) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}