#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// 检查是否全是字母
bool isAllLetters(const string& s) {
for(char c : s) {
if(!(c >= 'A' && c <= 'Z')) return false;
}
return true;
}
// 获取尾号(从右向左第一个数字)
int getTailNumber(const string& plate) {
for(int i = plate.length()-1; i >= 0; i--) {
if(plate[i] >= '0' && plate[i] <= '9') {
return plate[i] - '0';
}
}
return -1;
}
int main() {
string input;
int weekday;
getline(cin, input);
cin >> weekday;
// 检查输入是否为空
if(input.empty()) {
cout << "error" << endl;
return 0;
}
stringstream ss(input);
string plate;
vector<string> restricted;
while(getline(ss, plate, ',')) {
// 检查车牌格式
if(plate.length() != 5 || isAllLetters(plate)) {
cout << "error" << endl;
return 0;
}
int tail = getTailNumber(plate);
if(tail == -1) {
cout << "error" << endl;
return 0;
}
// 根据星期几判断限行
bool isRestricted = false;
switch(weekday) {
case 1: isRestricted = (tail == 1 || tail == 9); break;
case 2: isRestricted = (tail == 2 || tail == 8); break;
case 3: isRestricted = (tail == 3 || tail == 7); break;
case 4: isRestricted = (tail == 4 || tail == 6); break;
case 5: isRestricted = (tail == 5 || tail == 0); break;
}
if(isRestricted) restricted.push_back(plate);
}
if(restricted.empty()) cout << "none" << endl;
else {
for(size_t i = 0; i < restricted.size(); i++) {
cout << restricted[i];
if(i < restricted.size() - 1) cout << ",";
}
cout << endl;
}
return 0;
}
import java.util.*;
public class Main {
// 检查是否全是字母
static boolean isAllLetters(String s) {
for(char c : s.toCharArray()) {
if(!(c >= 'A' && c <= 'Z')) return false;
}
return true;
}
// 获取尾号
static int getTailNumber(String plate) {
for(int i = plate.length()-1; i >= 0; i--) {
if(Character.isDigit(plate.charAt(i))) {
return plate.charAt(i) - '0';
}
}
return -1;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
int weekday = sc.nextInt();
if(input.isEmpty()) {
System.out.println("error");
return;
}
String[] plates = input.split(",");
List<String> restricted = new ArrayList<>();
for(String plate : plates) {
if(plate.length() != 5 || isAllLetters(plate)) {
System.out.println("error");
return;
}
int tail = getTailNumber(plate);
if(tail == -1) {
System.out.println("error");
return;
}
boolean isRestricted = false;
switch(weekday) {
case 1: isRestricted = (tail == 1 || tail == 9); break;
case 2: isRestricted = (tail == 2 || tail == 8); break;
case 3: isRestricted = (tail == 3 || tail == 7); break;
case 4: isRestricted = (tail == 4 || tail == 6); break;
case 5: isRestricted = (tail == 5 || tail == 0); break;
}
if(isRestricted) restricted.add(plate);
}
if(restricted.isEmpty()) System.out.println("none");
else System.out.println(String.join(",", restricted));
}
}
def is_all_letters(s):
return all(c.isupper() for c in s)
def get_tail_number(plate):
for c in reversed(plate):
if c.isdigit():
return int(c)
return -1
plates = input().strip()
weekday = int(input())
if not plates:
print("error")
exit()
plates = plates.split(',')
restricted = []
for plate in plates:
if len(plate) != 5 or is_all_letters(plate):
print("error")
exit()
tail = get_tail_number(plate)
if tail == -1:
print("error")
exit()
is_restricted = False
if weekday == 1 and tail in [1, 9]: is_restricted = True
elif weekday == 2 and tail in [2, 8]: is_restricted = True
elif weekday == 3 and tail in [3, 7]: is_restricted = True
elif weekday == 4 and tail in [4, 6]: is_restricted = True
elif weekday == 5 and tail in [5, 0]: is_restricted = True
if is_restricted:
restricted.append(plate)
print("none" if not restricted else ",".join(restricted))