fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <chrono>
  4. #include <iomanip>
  5.  
  6. typedef std::chrono::high_resolution_clock Clock;
  7.  
  8. int main()
  9. {
  10. //auto t1 = Clock::now();
  11. std::string inp;
  12. std::cin >> inp;
  13. int day,month, year = 1980;
  14. day = month = 0;
  15. if (inp.size() == 16)
  16. {
  17. for (int i = 6; i > 0; --i)
  18. if (inp[i] == '1')
  19. year += pow(2, 6 - i);
  20. for (int i = 10; i > 6; --i)
  21. if (inp[i] == '1')
  22. month += pow(2, 10 - i);
  23. for (int i = 15; i > 10; --i)
  24. if (inp[i] == '1')
  25. day += pow(2, 15 - i);
  26. if (day == 0 || month == 0)
  27. std::cout << "ERROR" << std::endl;
  28. else
  29. {
  30. std::cout << year << "-";
  31. std::cout.fill('0');
  32. std::cout << std::setw(2) << month << "-" << std::setw(2) << day << std::endl;
  33. }
  34. }
  35. if (inp.size() == 10)
  36. {
  37. char out[17] = "0000000000000000";
  38. std::string tyear = "";
  39. copy(inp.begin(), inp.begin() + 4, tyear.begin());
  40. std::string tmonth = "";
  41. copy(inp.begin() + 5, inp.begin() + 7, tmonth.begin());
  42. std::string tday = "";
  43. copy(inp.begin() + 8, inp.end(), tday.begin());
  44. year = atoi(tyear.c_str()) - 1980;
  45. month = atoi(tmonth.c_str());
  46. day = atoi(tday.c_str());
  47. int i;
  48. for (i = 6; i >= 0 && year / 2; --i)
  49. {
  50. if (year % 2)
  51. out[i] = '1';
  52. else
  53. out[i] = '0';
  54. year /= 2;
  55. }
  56. out[i] = '1';
  57. for (i = 10; i > 6 && month / 2; --i)
  58. {
  59. if (month % 2)
  60. out[i] = '1';
  61. else
  62. out[i] = '0';
  63. month /= 2;
  64. }
  65. out[i] = '1';
  66. for (i = 15; i > 10; --i)
  67. {
  68. if (day % 2)
  69. out[i] = '1';
  70. else
  71. out[i] = '0';
  72. day /= 2;
  73. }
  74. out[i] = '1';
  75. out[16] = '\0';
  76. std::cout << out << std::endl;
  77.  
  78. }
  79.  
  80. //auto t2 = Clock::now();
  81. //std::cout << "Delta t2-t1: "
  82. //<< std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count()
  83. //<< " nanoseconds" << std::endl;
  84.  
  85. return 0;
  86. }
  87.  
Success #stdin #stdout 0s 4460KB
stdin
0011101100110010
stdout
2009-09-18