Kaidul

Date to day name conversion

Sep 13th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define _ ios_base:sync_with_stdio(0);cin.tie(0);
  3. using namespace std;
  4. /*** typedef ***/
  5. #define MEMSET_INF 127
  6. #define MEMSET_HALF_INF 63
  7. #define stream istringstream
  8. #define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
  9. #define repl(i,n) for(__typeof(n) i=1; i<=(n); i++)
  10. #define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
  11. #define INF (1<<30)
  12. #define PI acos(-1.0)
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define all(x) x.begin(),x.end()
  16. #define mem(x,y) memset(x,y,sizeof(x))
  17. #define memsp(x) mem(x,MEMSET_INF)
  18. #define memdp(x) mem(x,-1)
  19. #define memca(x) mem(x,0)
  20. #define eps 1e-9
  21. #define pii pair<int,int>
  22. #define pmp make_pair
  23. #define ft first
  24. #define sd second
  25. #define vi vector<int>
  26. #define vpii vector<pii>
  27. #define si set<int>
  28. #define msi map<string , int >
  29. #define mis map<int , string >
  30. typedef long long i64;
  31. typedef unsigned long long ui64;
  32. /** function **/
  33. #define SDi(x) sf("%d",&x)
  34. #define SDl(x) sf("%lld",&x)
  35. #define SDs(x) sf("%s",x)
  36. #define SD2(x,y) sf("%d%d",&x,&y)
  37. #define SD3(x,y,z) sf("%d%d%d",&x,&y,&z)
  38. #define pf printf
  39. #define print(x) pf("%d ", x)
  40. #define println(x) pf("%d\n", x)
  41. #define sf scanf
  42. #define READ(f) freopen(f, "r", stdin)
  43. #define WRITE(f) freopen(f, "w", stdout)
  44.  
  45.  
  46. bool isLeapYear(int year) {
  47.     return (year % 4 == 0);
  48. }
  49. map <int, int> monthTable;
  50. bool isFriday (string date) {
  51.     int year = atoi( (date.substr(0, 4)).c_str() );
  52.     int lastTwo = atoi((date.substr (2, 2)).c_str());
  53.     int century = atoi((date.substr (0, 2)).c_str());
  54.     int month = atoi( (date.substr(5, 2)).c_str() );
  55.     int day = atoi( (date.substr(8, 2)).c_str() );
  56.     int monthTableValue;
  57.     if (isLeapYear(lastTwo) && (month == 1 || month == 2)) {
  58.         monthTableValue = monthTable[month] - 1;
  59.     } else {
  60.         monthTableValue = monthTable[month];
  61.     }
  62.     int c = 0;
  63.     switch (century % 4) {
  64.     case 0:
  65.         c = 6;
  66.         break;
  67.     case 1:
  68.         c = 4;
  69.         break;
  70.     case 2:
  71.         c = 2;
  72.         break;
  73.     case 3:
  74.         c = 0;
  75.         break;
  76.     default:
  77.         break;
  78.     }
  79.     int days = ( day + monthTableValue + lastTwo + int (floor(lastTwo / 4)) +  c) % 7;
  80.     if (days == 5 && day == 13)
  81.         return true;
  82.     return false;
  83. }
  84. int main() {
  85. #ifndef ONLINE_JUDGE
  86.     READ("input.txt");
  87. #endif
  88.     monthTable[1] = 0;
  89.     monthTable[2] = 3;
  90.     monthTable[3] = 3;
  91.     monthTable[4] = 6;
  92.     monthTable[5] = 1;
  93.     monthTable[6] = 4;
  94.     monthTable[7] = 6;
  95.     monthTable[8] = 2;
  96.     monthTable[9] = 5;
  97.     monthTable[10] = 0;
  98.     monthTable[11] = 3;
  99.     monthTable[12] = 5;
  100.     int tcase;
  101.     string date;
  102.     SDi(tcase);
  103.     int total = 0;
  104.     while(tcase--) {
  105.         cin >> date;
  106.         total += isFriday(date);
  107.     }
  108.     println(total);
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment