fork(1) download
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20. #include <cstring>
  21. #include <math.h>
  22. #define lli long long int
  23. using namespace std;
  24.  
  25. int main(){
  26. int f;
  27. cin >> f;
  28. string x;
  29. cin >> x;
  30. int a[5];
  31. string r;
  32. for(int i = 0; i < 5; i++){
  33. if(i == 2){
  34. continue;
  35. }
  36. r = x[i];
  37. a[i] = std::stoi(r);
  38. }
  39. int hours = (a[0] * 10) + a[1];
  40. int minutes = (a[3] * 10) + a[1];
  41.  
  42. if(f==12){
  43. if(a[0] == 0){
  44. if(a[1] == 0){
  45. a[1] = 1;
  46. }
  47. }
  48. if(a[0] > 1){
  49. a[0] = 1;
  50. }
  51. if(a[1] > 2){
  52. a[1] = 2;
  53. }
  54.  
  55.  
  56. if(a[3] > 5){
  57. a[3] = 5;
  58. }
  59.  
  60. }
  61. else{
  62.  
  63.  
  64. if(a[0] > 2){
  65. a[0] = 0;
  66. }
  67. else if(a[0]== 2){
  68. if(a[1] > 3){
  69. a[1] = 0;
  70. }
  71. }
  72.  
  73.  
  74. if(a[3] > 5){
  75. a[3] = 5;
  76. }
  77. }
  78.  
  79. for(int i = 0; i < 5; i++){
  80. if(i == 2){
  81. cout << ":";
  82. continue;
  83. }
  84. cout << a[i];
  85. }
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
Runtime error #stdin #stdout #stderr 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi