Advertisement
Malinovsky239

Untitled

Oct 31st, 2011
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. char s[10];
  10. int len[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, j;
  11. string res[10];
  12.  
  13. int main() {
  14.     freopen("chronicle.in", "r", stdin);
  15.     freopen("chronicle.out", "w", stdout);
  16.  
  17.     int a[3];
  18.     scanf("%d/%d/%d", &a[0], &a[1], &a[2]);
  19.  
  20.     int p[] = {0, 1, 2};
  21.     bool ok = false;
  22.  
  23.     do {
  24.         int d = a[ p[0] ];
  25.         int m = a[ p[1] ];
  26.         int y = a[ p[2] ];
  27.  
  28.         if (m > 12 || m == 0 || d == 0)
  29.             continue;
  30.    
  31.         m--;
  32.  
  33.         if (y % 4 == 0 && y != 0)
  34.             len[1]++;
  35.  
  36.         if (d <= len[m]) {
  37.             sprintf(s, "%02d/%02d/%02d\n", d, m + 1, y);
  38.             for (int i = 0; i < 8; i++)
  39.                 res[j] += s[i];
  40.             j++;
  41.             ok = true;
  42.         }
  43.  
  44.         if (y % 4 == 0 && y != 0)
  45.             len[1]--;
  46.         }
  47.     while (next_permutation(p, p + 3));
  48.  
  49.     if (!ok)
  50.             puts("No such date\n");
  51.     else {
  52.         sort(res, res + j);
  53.         cout << res[0] << endl;
  54.         for (int i = 1; i < j; i++)
  55.             if (res[i] != res[i - 1])
  56.                 cout << res[i] << endl;
  57.     }
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement