#include <iostream> #include <string.h> #include <vector> #include <math.h> #include <stdio.h> #include <set>; #include <map> #include <algorithm> using namespace std; int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; set<int> s; bool IsLeap(int y) { return (y % 100 == 0 && y % 400 == 0) || (y % 100 != 0 && y % 4 == 0); } int GetDaysInNonth(int y, int m) { return (m == 2 && IsLeap(y)) ? days[m-1] + 1 : days[m-1]; } int RelativeTo(int y, int m, int d) { int sum = 0; for (int i = 1700; i < y; i++) for (int j = 0; j < 12; j++) sum += GetDaysInNonth(i, j+1); for (int i = 1; i < m; i++) sum += GetDaysInNonth(y, i); sum = sum + d - 1; return sum - 110245; } int String2Int(char str[]) { int sum = 0; for (int i = 0; i < strlen(str); i++) sum = 10 * sum + str[i] - '0'; return sum; } bool IsValid(int y, int m, int d) { return y >= 1700 && y <= 2299 && m >= 1 && m <= 12 && d >= 1 && d <= GetDaysInNonth(y, m); } bool ContainDelimiter(char str[]) { for (int i = 0; i < strlen(str); i++) if (str[i] < '0' || str[i] > '9') return true; return false; } void Insert(char y[], char m[], char d[]) { if (strlen(m) <= 2 && strlen(d) <= 2) { if (strlen(y) <= 2) { for (int i = 1700; i <= 2200; i += 100) if (IsValid(i + String2Int(y), String2Int(m), String2Int(d)))s.insert(RelativeTo(i + String2Int(y), String2Int(m), String2Int(d))); } else if (strlen(y) == 4) { if (IsValid(String2Int(y), String2Int(m), String2Int(d))) s.insert(RelativeTo(String2Int(y), String2Int(m), String2Int(d))); } } } void ValidateAll(char s0[], char s1[], char s2[]) { Insert(s0, s1, s2); Insert(s0, s2, s1); Insert(s1, s0, s2); Insert(s1, s2, s0); Insert(s2, s0, s1); Insert(s2, s1, s0); } int main() { int t; char line[15]; char s0[15], s1[15], s2[15]; cin >> t; for (int i = 0; i < t; i++) { cin >> line; s.clear(); printf("Scenario #%d:n", i+1); if (ContainDelimiter(line)) { int j, index = 0; for (j = 0; line[j] >= '0' && line[j] <= '9'; j++) s0[index++] = line[j]; s0[index] = ' '; index = 0; for (j++; line[j] >= '0' && line[j] <= '9'; j++) s1[index++] = line[j]; s1[index] = ' '; index = 0; for (j++; j < strlen(line); j++) s2[index++] = line[j]; s2[index] = ' '; ValidateAll(s0, s1, s2); } else { for (int j = 0; j < strlen(line)-2; j++) for (int k = j+1; k < strlen(line)-1; k++) { s0[0] = ' ', s1[0] = ' ', s2[0] = ' '; strncpy(s0, line, j+1);s0[j+1] = ' ';strncpy(s1, line+j+1, k-j);s1[k-j] = ' ';strncpy(s2, line+k+1, strlen(line)-k+1);s2[strlen(line)-k+1] = ' ';ValidateAll(s0, s1, s2); } } if (s.size() == 0) cout << "Illegal date" << endl; else for (set<int>::iterator iter = s.begin(); iter != s.end(); iter++) cout << *iter << endl; cout << endl; } }