50051. Valid License Plates
難度:3.8/5
想好再下手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#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define plate_1 1
#define plate_2 2
int cmp(const void* a, const void* b){
return strcmp((char*)a, (char*)b);
}
bool check_1(char* s){
if(s[2] == '-'){
for(int i = 0; i < 7; i++){
if(i == 2) continue;
if(!(isalpha(s[i]) || isdigit(s[i]))) return false;
}
}
else if(s[3] == '-'){
for(int i = 0; i < 7; i++){
if(i == 3) continue;
if(!(isalpha(s[i]) || isdigit(s[i]))) return false;
}
}
else{
return false;;
}
return true;
}
bool check_2(char* s){
bool have_digit = false;
int sum = 0;
for(int i = 0; i < 7; i++){
if(isdigit(s[i])){
have_digit = true;
sum += (s[i] - '0');
}
}
return have_digit && (sum % 7 != 0);
}
bool check_3(char* s){
int count[128] = {0};
for(int i = 0; i < 7; i++){
count[s[i]] += 1;
}
for(int i = 0; i < 128; i++){
if(count[i] >= 3) return false;
}
return true;
}
bool check_4(char* s){
for(int i = 0; i < 7 - 1; i++){
if(s[i] == s[i + 1] && s[i] == '4'){
return false;
}
}
return true;
}
static inline bool check(char* s){
return check_1(s) && check_2(s) && check_3(s) && check_4(s);
}
int main(){
int n; scanf("%d", &n);
char s1[32][10], s2[32][10];
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < n; i++){
char s[10]; scanf("%s", s);
if(check(s)){
if(s[2] == '-'){
strcpy(s1[cnt1++], s);
}
else if(s[3] == '-'){
strcpy(s2[cnt2++], s);
}
}
}
qsort(s1, cnt1, sizeof(s1[0]), cmp);
qsort(s2, cnt2, sizeof(s2[0]), cmp);
for(int i = 0; i < cnt1; i++) printf("%s\n", s1[i]);
for(int i = 0; i < cnt2; i++) printf("%s\n", s2[i]);
}