output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int format;
string st, h, m;
int main() {
cin >> format;
cin >> st;
int ans = 0;
if (st[3] >= '6') {
ans++;
st[3] = '0';
}
if (format == 24) {
if (st[0] > '2') {
st[0] = '1';
ans++;
}
if (st[0] == '2' && st[1] > '3') {
ans++;
st[1] = '1';
}
}
if (format == 12) {
if (st[0] == '0' && st[1] == '0') {
ans++;
st[1] = '1';
} else if (st[0] > '1') {
ans++;
if (st[1] == '0') {
st[0] = '1';
} else {
st[0] = '0';
}
} else if (st[0] == '1' && st[1] > '2') {
ans++;
st[0] = '0';
}
}
cout << st << endl;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int format;
string st, h, m;
int main() {
cin >> format;
cin >> st;
int ans = 0;
if (st[3] >= '6') {
ans++;
st[3] = '0';
}
if (format == 24) {
if (st[0] > '2') {
st[0] = '1';
ans++;
}
if (st[0] == '2' && st[1] > '3') {
ans++;
st[1] = '1';
}
}
if (format == 12) {
if (st[0] == '0' && st[1] == '0') {
ans++;
st[1] = '1';
} else if (st[0] > '1') {
ans++;
if (st[1] == '0') {
st[0] = '1';
} else {
st[0] = '0';
}
} else if (st[0] == '1' && st[1] > '2') {
ans++;
st[0] = '0';
}
}
cout << st << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int hours;
cin >> hours;
int h, m;
cin >> h;
cin.ignore();
cin >> m;
while (m > 59) m -= 10;
if (hours == 24) {
while (h > 23) {
h -= 10;
}
} else {
while (h > 12) {
h -= 10;
}
if (!h) {
h = 10;
}
}
if (h < 10) cout << '0';
cout << h;
cout << ':';
if (m < 10) cout << '0';
cout << m;
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int hours;
cin >> hours;
int h, m;
cin >> h;
cin.ignore();
cin >> m;
while (m > 59) m -= 10;
if (hours == 24) {
while (h > 23) {
h -= 10;
}
} else {
while (h > 12) {
h -= 10;
}
if (!h) {
h = 10;
}
}
if (h < 10) cout << '0';
cout << h;
cout << ':';
if (m < 10) cout << '0';
cout << m;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long i, j, m, n, p, q, r, s, a, b;
string aa, bb;
int main() {
cin >> n;
scanf("%ld:%ld", &a, &b);
if (n == 12) {
if (a == 0)
aa = "01";
else if (a >= 13) {
p = a % 10;
if (p == 0) {
aa = "10";
} else
aa += '0', aa += (a % 10 + 48);
} else {
p = a % 10;
a /= 10;
q = a % 10;
aa += (q + 48), aa += (p + 48);
}
if (b == 60)
bb = "00";
else if (b > 60) {
bb += '0', bb += (b % 10 + 48);
} else {
p = b % 10;
b /= 10;
q = b % 10;
bb += (q + 48), bb += (p + 48);
}
cout << aa << ":" << bb;
} else {
if (a >= 24) {
aa += '0', aa += (a % 10 + 48);
} else {
p = a % 10;
a /= 10;
q = a % 10;
aa += (q + 48), aa += (p + 48);
}
if (b == 60)
bb = "00";
else if (b > 60) {
bb += '0', bb += (b % 10 + 48);
} else {
p = b % 10;
b /= 10;
q = b % 10;
bb += (q + 48), bb += (p + 48);
}
cout << aa << ":" << bb;
}
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long i, j, m, n, p, q, r, s, a, b;
string aa, bb;
int main() {
cin >> n;
scanf("%ld:%ld", &a, &b);
if (n == 12) {
if (a == 0)
aa = "01";
else if (a >= 13) {
p = a % 10;
if (p == 0) {
aa = "10";
} else
aa += '0', aa += (a % 10 + 48);
} else {
p = a % 10;
a /= 10;
q = a % 10;
aa += (q + 48), aa += (p + 48);
}
if (b == 60)
bb = "00";
else if (b > 60) {
bb += '0', bb += (b % 10 + 48);
} else {
p = b % 10;
b /= 10;
q = b % 10;
bb += (q + 48), bb += (p + 48);
}
cout << aa << ":" << bb;
} else {
if (a >= 24) {
aa += '0', aa += (a % 10 + 48);
} else {
p = a % 10;
a /= 10;
q = a % 10;
aa += (q + 48), aa += (p + 48);
}
if (b == 60)
bb = "00";
else if (b > 60) {
bb += '0', bb += (b % 10 + 48);
} else {
p = b % 10;
b /= 10;
q = b % 10;
bb += (q + 48), bb += (p + 48);
}
cout << aa << ":" << bb;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[10];
scanf("%d%s", &n, s);
int a = (s[0] - '0') * 10 + (s[1] - '0');
int b = (s[3] - '0') * 10 + (s[4] - '0');
if (n == 12) {
if (a == 0)
s[1] = '1';
else if (a > 12) {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
} else if (a >= 24)
s[0] = '0';
if (b >= 60) s[3] = '0';
printf("%s\n", s);
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[10];
scanf("%d%s", &n, s);
int a = (s[0] - '0') * 10 + (s[1] - '0');
int b = (s[3] - '0') * 10 + (s[4] - '0');
if (n == 12) {
if (a == 0)
s[1] = '1';
else if (a > 12) {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
} else if (a >= 24)
s[0] = '0';
if (b >= 60) s[3] = '0';
printf("%s\n", s);
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int f, h, m;
scanf("%d", &f);
scanf("%d:%d", &h, &m);
if (m > 59) m %= 10;
if (f == 24 && h >= 24) h = 10 + h % 10;
if (f == 12 && h == 0) h = 1;
if (f == 12 && h > 12) {
if (h % 10 == 0)
h = 10;
else
h %= 10;
}
if (h < 10) printf("0");
printf("%d:", h);
if (m < 10) printf("0");
printf("%d\n", m);
}
|
### Prompt
Create a solution in Cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int f, h, m;
scanf("%d", &f);
scanf("%d:%d", &h, &m);
if (m > 59) m %= 10;
if (f == 24 && h >= 24) h = 10 + h % 10;
if (f == 12 && h == 0) h = 1;
if (f == 12 && h > 12) {
if (h % 10 == 0)
h = 10;
else
h %= 10;
}
if (h < 10) printf("0");
printf("%d:", h);
if (m < 10) printf("0");
printf("%d\n", m);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int x;
string a;
void input() {
cin >> x;
cin >> a;
}
void solve() {
if ((a[3] - '0') >= 6) {
a[3] = '0';
}
int h = 10 * (a[0] - '0') + (a[1] - '0');
if (x == 24) {
if (h >= 24) {
a[0] = '0';
}
} else {
if (h > 12) {
if (a[1] != '0') {
a[0] = '0';
} else {
a[0] = '1';
}
} else if (h == 0) {
a[0] = '1';
}
}
cout << a << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int x;
string a;
void input() {
cin >> x;
cin >> a;
}
void solve() {
if ((a[3] - '0') >= 6) {
a[3] = '0';
}
int h = 10 * (a[0] - '0') + (a[1] - '0');
if (x == 24) {
if (h >= 24) {
a[0] = '0';
}
} else {
if (h > 12) {
if (a[1] != '0') {
a[0] = '0';
} else {
a[0] = '1';
}
} else if (h == 0) {
a[0] = '1';
}
}
cout << a << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, s, a, b;
char c;
string str;
cin >> n;
cin >> str;
m = ((str[0] - '0') * 10) + (str[1] - '0');
s = ((str[3] - '0') * 10) + (str[4] - '0');
if (n == 12) {
if (m < 1) {
m = 1;
}
if (m > 12) {
b = m % 10;
a = m / 10;
m = b;
if (m == 0) m = 10;
}
} else if (n == 24) {
if (m > 23) {
m = m % 10;
}
}
if (s > 59) {
a = s / 10;
b = s % 10;
if (a > 5) a = 5;
s = a * 10 + b;
}
printf("%02d:%02d\n", m, s);
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, s, a, b;
char c;
string str;
cin >> n;
cin >> str;
m = ((str[0] - '0') * 10) + (str[1] - '0');
s = ((str[3] - '0') * 10) + (str[4] - '0');
if (n == 12) {
if (m < 1) {
m = 1;
}
if (m > 12) {
b = m % 10;
a = m / 10;
m = b;
if (m == 0) m = 10;
}
} else if (n == 24) {
if (m > 23) {
m = m % 10;
}
}
if (s > 59) {
a = s / 10;
b = s % 10;
if (a > 5) a = 5;
s = a * 10 + b;
}
printf("%02d:%02d\n", m, s);
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int a, b, c;
scanf("%d", &c);
scanf("%02d:%02d", &a, &b);
if (b >= 60) b = b % 10;
if (a > c || a == 24) a = a % 10;
if (c == 12 && a == 0) a = 10;
printf("%02d:%02d", a, b);
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int a, b, c;
scanf("%d", &c);
scanf("%02d:%02d", &a, &b);
if (b >= 60) b = b % 10;
if (a > c || a == 24) a = a % 10;
if (c == 12 && a == 0) a = 10;
printf("%02d:%02d", a, b);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int hours;
scanf("%d", &hours);
int h, s;
char c;
scanf(" %d %c %d", &h, &c, &s);
if (hours == 12)
while (h > hours) h -= 10;
if (hours == 24)
while (h >= hours) h -= 10;
while (s > 59) s -= 60;
if (hours == 12 && h == 0) h = 1;
if (h < 10)
printf("%d%d%c", 0, h, ':');
else
printf("%d%c", h, ':');
if (s < 10)
printf("%d%d", 0, s);
else
printf("%d", s);
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int hours;
scanf("%d", &hours);
int h, s;
char c;
scanf(" %d %c %d", &h, &c, &s);
if (hours == 12)
while (h > hours) h -= 10;
if (hours == 24)
while (h >= hours) h -= 10;
while (s > 59) s -= 60;
if (hours == 12 && h == 0) h = 1;
if (h < 10)
printf("%d%d%c", 0, h, ':');
else
printf("%d%c", h, ':');
if (s < 10)
printf("%d%d", 0, s);
else
printf("%d", s);
}
```
|
#include <bits/stdc++.h>
const int maxn = 5e2 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
long long f = 1;
while (q) {
if (q & 1) f = f * p;
p = p * p;
q >>= 1;
}
return f;
}
long long my_min(long long x, long long y) { return x > y ? y : x; };
int main() {
int m;
char str[100];
while (scanf("%d", &m) != EOF) {
int hour;
int sec;
scanf("%s", str);
hour = (str[0] - '0') * 10 + (str[1] - '0');
sec = (str[3] - '0') * 10 + (str[4] - '0');
if (m == 12) {
if (hour == 0) {
str[1] = '1';
} else if (hour > 12) {
if (str[1] == '0') {
str[0] = '1';
} else {
str[0] = '0';
}
}
} else {
if (hour >= 24) {
str[0] = '0';
}
}
if (sec >= 60) {
str[3] = '0';
}
printf("%s\n", str);
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
const int maxn = 5e2 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
long long f = 1;
while (q) {
if (q & 1) f = f * p;
p = p * p;
q >>= 1;
}
return f;
}
long long my_min(long long x, long long y) { return x > y ? y : x; };
int main() {
int m;
char str[100];
while (scanf("%d", &m) != EOF) {
int hour;
int sec;
scanf("%s", str);
hour = (str[0] - '0') * 10 + (str[1] - '0');
sec = (str[3] - '0') * 10 + (str[4] - '0');
if (m == 12) {
if (hour == 0) {
str[1] = '1';
} else if (hour > 12) {
if (str[1] == '0') {
str[0] = '1';
} else {
str[0] = '0';
}
}
} else {
if (hour >= 24) {
str[0] = '0';
}
}
if (sec >= 60) {
str[3] = '0';
}
printf("%s\n", str);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h0, m1, m0;
int type;
char c;
cin >> type;
int hour, min;
cin >> hour >> c >> min;
h1 = hour / 10;
h0 = hour % 10;
m1 = min / 10;
m0 = min % 10;
if (m1 > 5) m1 = 4;
if (type == 12) {
if (h1 == 0 && h0 != 0) {
;
} else if (h1 == 1 && (h0 == 0 || h0 == 1 || h0 == 2)) {
;
} else {
h1 = 0;
}
if (h1 == 0 && h0 == 0) h1 = 1;
} else {
if (h1 == 0 || h1 == 1) {
;
} else if (h1 == 2 && (h0 == 0 || h0 == 1 || h0 == 2 || h0 == 3)) {
;
} else {
h1 = 0;
}
}
cout << h1 << h0 << ":" << m1 << m0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h0, m1, m0;
int type;
char c;
cin >> type;
int hour, min;
cin >> hour >> c >> min;
h1 = hour / 10;
h0 = hour % 10;
m1 = min / 10;
m0 = min % 10;
if (m1 > 5) m1 = 4;
if (type == 12) {
if (h1 == 0 && h0 != 0) {
;
} else if (h1 == 1 && (h0 == 0 || h0 == 1 || h0 == 2)) {
;
} else {
h1 = 0;
}
if (h1 == 0 && h0 == 0) h1 = 1;
} else {
if (h1 == 0 || h1 == 1) {
;
} else if (h1 == 2 && (h0 == 0 || h0 == 1 || h0 == 2 || h0 == 3)) {
;
} else {
h1 = 0;
}
}
cout << h1 << h0 << ":" << m1 << m0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int N = 100000;
int dif(string s1, string s2) {
int r = 0;
for (int i = 0; i < s1.length(); i++)
if (s1[i] != s2[i]) {
r++;
}
return r;
}
int main() {
ios_base::sync_with_stdio(0);
int n, ansDif = INF;
cin >> n;
string s, ans;
cin >> s;
if (n == 12) {
for (int h = 1; h <= 12; h++)
for (int m = 0; m < 60; m++) {
string x1 = to_string(h);
string y1 = to_string(m);
if (h < 10) {
x1 = "0" + x1;
}
if (m < 10) {
y1 = "0" + y1;
}
string s1 = x1 + ":" + y1;
if (dif(s1, s) < ansDif) {
ansDif = dif(s1, s);
ans = s1;
}
}
} else {
for (int h = 0; h <= 23; h++)
for (int m = 0; m < 60; m++) {
string x1 = to_string(h);
string y1 = to_string(m);
if (h < 10) {
x1 = "0" + x1;
}
if (m < 10) {
y1 = "0" + y1;
}
string s1 = x1 + ":" + y1;
if (dif(s1, s) < ansDif) {
ansDif = dif(s1, s);
ans = s1;
}
}
}
cout << ans << endl;
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int N = 100000;
int dif(string s1, string s2) {
int r = 0;
for (int i = 0; i < s1.length(); i++)
if (s1[i] != s2[i]) {
r++;
}
return r;
}
int main() {
ios_base::sync_with_stdio(0);
int n, ansDif = INF;
cin >> n;
string s, ans;
cin >> s;
if (n == 12) {
for (int h = 1; h <= 12; h++)
for (int m = 0; m < 60; m++) {
string x1 = to_string(h);
string y1 = to_string(m);
if (h < 10) {
x1 = "0" + x1;
}
if (m < 10) {
y1 = "0" + y1;
}
string s1 = x1 + ":" + y1;
if (dif(s1, s) < ansDif) {
ansDif = dif(s1, s);
ans = s1;
}
}
} else {
for (int h = 0; h <= 23; h++)
for (int m = 0; m < 60; m++) {
string x1 = to_string(h);
string y1 = to_string(m);
if (h < 10) {
x1 = "0" + x1;
}
if (m < 10) {
y1 = "0" + y1;
}
string s1 = x1 + ":" + y1;
if (dif(s1, s) < ansDif) {
ansDif = dif(s1, s);
ans = s1;
}
}
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string str, cmp, sec;
int main() {
ios::sync_with_stdio(false);
int i, j, x, y, n, m;
cmp = sec = "";
cin >> n;
if (n == 24) {
cin >> str;
cmp = cmp + str[0];
cmp = cmp + str[1];
sec = sec + str[3];
sec = sec + str[4];
if (cmp > "23") str[0] = '0';
if (sec > "59") str[3] = '0';
cout << str;
} else {
cin >> str;
cmp = cmp + str[0];
cmp = cmp + str[1];
sec = sec + str[3];
sec = sec + str[4];
if (cmp > "12" && str[1] != '0')
str[0] = '0';
else if (cmp > "12")
str[0] = '1';
else if (cmp == "00")
str[0] = '1';
if (sec > "59") str[3] = '0';
cout << str;
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string str, cmp, sec;
int main() {
ios::sync_with_stdio(false);
int i, j, x, y, n, m;
cmp = sec = "";
cin >> n;
if (n == 24) {
cin >> str;
cmp = cmp + str[0];
cmp = cmp + str[1];
sec = sec + str[3];
sec = sec + str[4];
if (cmp > "23") str[0] = '0';
if (sec > "59") str[3] = '0';
cout << str;
} else {
cin >> str;
cmp = cmp + str[0];
cmp = cmp + str[1];
sec = sec + str[3];
sec = sec + str[4];
if (cmp > "12" && str[1] != '0')
str[0] = '0';
else if (cmp > "12")
str[0] = '1';
else if (cmp == "00")
str[0] = '1';
if (sec > "59") str[3] = '0';
cout << str;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int h, m, f;
cin >> f >> s;
h = (s[0] - 48) * 10 + (s[1] - 48);
m = (s[3] - 48) * 10 + (s[4] - 48);
if (f == 24) {
if (h >= 24) {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
} else {
if (h > 12) {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
if (s[0] == '0' && s[1] == '0') s[1] = '1';
}
if (m >= 60) {
if (s[4] != '0')
s[3] = '0';
else
s[3] = '1';
}
cout << s;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int h, m, f;
cin >> f >> s;
h = (s[0] - 48) * 10 + (s[1] - 48);
m = (s[3] - 48) * 10 + (s[4] - 48);
if (f == 24) {
if (h >= 24) {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
} else {
if (h > 12) {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
if (s[0] == '0' && s[1] == '0') s[1] = '1';
}
if (m >= 60) {
if (s[4] != '0')
s[3] = '0';
else
s[3] = '1';
}
cout << s;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int format;
cin >> format;
int hour, minute;
char isto;
cin >> hour >> isto >> minute;
if (format == 12) {
if (hour > 12 && hour % 10 != 0)
hour = hour % 10;
else if (hour > 12 && hour % 10 == 0)
hour = 10;
else if (hour == 0)
hour = 1;
} else {
if (hour > 23) hour = hour % 10;
}
if (minute > 59) minute = minute % 60;
if (hour < 10) {
cout << "0" << hour << isto;
} else {
cout << hour << isto;
}
if (minute < 10) {
cout << "0" << minute;
} else
cout << minute;
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int format;
cin >> format;
int hour, minute;
char isto;
cin >> hour >> isto >> minute;
if (format == 12) {
if (hour > 12 && hour % 10 != 0)
hour = hour % 10;
else if (hour > 12 && hour % 10 == 0)
hour = 10;
else if (hour == 0)
hour = 1;
} else {
if (hour > 23) hour = hour % 10;
}
if (minute > 59) minute = minute % 60;
if (hour < 10) {
cout << "0" << hour << isto;
} else {
cout << hour << isto;
}
if (minute < 10) {
cout << "0" << minute;
} else
cout << minute;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 6005;
const long long oo = 1e6;
int main() {
int n;
string s;
cin >> n >> s;
int a = (s[3] - '0') * 10 + s[4] - '0';
if (a > 59) {
s[3] = '0';
}
if (n == 24) {
int a = (s[0] - '0') * 10 + s[1] - '0';
if (a > 23) {
s[0] = '0';
}
}
if (n == 12) {
int a = (s[0] - '0') * 10 + s[1] - '0';
if (a == 0) {
s[0] = '1';
}
if (a > 12) {
if (a % 10 == 0)
s[0] = '1';
else
s[0] = '0';
}
}
cout << s;
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 6005;
const long long oo = 1e6;
int main() {
int n;
string s;
cin >> n >> s;
int a = (s[3] - '0') * 10 + s[4] - '0';
if (a > 59) {
s[3] = '0';
}
if (n == 24) {
int a = (s[0] - '0') * 10 + s[1] - '0';
if (a > 23) {
s[0] = '0';
}
}
if (n == 12) {
int a = (s[0] - '0') * 10 + s[1] - '0';
if (a == 0) {
s[0] = '1';
}
if (a > 12) {
if (a % 10 == 0)
s[0] = '1';
else
s[0] = '0';
}
}
cout << s;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double GRS = (1 + sqrt(5)) / 2;
long long power(int X, int P) {
long long ans = 1;
for (int i = 1; i <= P; i++) {
ans = ans * (long long)X;
}
return ans;
}
long long ABS(long long A, long long B) {
long long ret = A - B;
if (ret < 0) return -ret;
return ret;
}
long long MOD = 1000000007;
long long bigmod(long long a, long long b) {
long long x = 1, y = a % MOD;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x > MOD) x %= MOD;
}
y = (y * y);
if (y > MOD) y %= MOD;
b /= 2;
}
return x;
}
long long MODINVERSE(long long a) { return bigmod(a, MOD - 2); }
long long ncrdp[900][1000];
long long NCR(int n, int r) {
if (r == 1)
return n;
else if (n == r)
return 1;
else {
if (ncrdp[n][r] != -1)
return ncrdp[n][r];
else {
ncrdp[n][r] = NCR(n - 1, r) + NCR(n - 1, r - 1);
return ncrdp[n][r];
}
}
}
const int MAXN = 1005;
int status[(MAXN / 32) + 10];
vector<int> primelist;
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
int SET(int n, int pos) { return n = n | (1 << pos); }
void sieve() {
int sqrtN = int(sqrt(MAXN));
status[1 >> 5] = SET(status[1 >> 5], 1 & 31);
for (int i = 3; i <= sqrtN; i = i + 2) {
if (check(status[i >> 5], i & 31) == 0) {
for (int j = i * i; j <= MAXN; j = j + (i << 1)) {
status[j >> 5] = SET(status[j >> 5], j & 31);
}
}
}
primelist.push_back(2);
for (int i = 3; i <= MAXN; i = i + 2) {
if (check(status[i >> 5], i & 31) == 0) {
primelist.push_back(i);
}
}
}
int main() {
int t, hh, mm;
scanf("%d", &t);
scanf("%d:%d", &hh, &mm);
if (t == 24) {
if (hh < 24) {
if (hh < 10) {
printf("0%d:", hh);
} else {
printf("%d:", hh);
}
} else {
printf("0%d:", hh % 10);
}
if (mm < 60) {
if (mm < 10) {
printf("0%d", mm);
} else {
printf("%d", mm);
}
} else {
printf("0%d", mm % 10);
}
} else {
if (hh == 0) {
printf("01:");
} else if (hh > 12) {
if (hh % 10 == 0) {
printf("10:");
} else {
printf("0%d:", hh % 10);
}
} else {
if (hh < 10)
printf("0%d:", hh);
else
printf("%d:", hh);
}
if (mm < 60) {
if (mm < 10)
printf("0%d", mm);
else
printf("%d", mm);
} else {
printf("0%d", mm % 10);
}
}
}
|
### Prompt
Generate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double GRS = (1 + sqrt(5)) / 2;
long long power(int X, int P) {
long long ans = 1;
for (int i = 1; i <= P; i++) {
ans = ans * (long long)X;
}
return ans;
}
long long ABS(long long A, long long B) {
long long ret = A - B;
if (ret < 0) return -ret;
return ret;
}
long long MOD = 1000000007;
long long bigmod(long long a, long long b) {
long long x = 1, y = a % MOD;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x > MOD) x %= MOD;
}
y = (y * y);
if (y > MOD) y %= MOD;
b /= 2;
}
return x;
}
long long MODINVERSE(long long a) { return bigmod(a, MOD - 2); }
long long ncrdp[900][1000];
long long NCR(int n, int r) {
if (r == 1)
return n;
else if (n == r)
return 1;
else {
if (ncrdp[n][r] != -1)
return ncrdp[n][r];
else {
ncrdp[n][r] = NCR(n - 1, r) + NCR(n - 1, r - 1);
return ncrdp[n][r];
}
}
}
const int MAXN = 1005;
int status[(MAXN / 32) + 10];
vector<int> primelist;
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
int SET(int n, int pos) { return n = n | (1 << pos); }
void sieve() {
int sqrtN = int(sqrt(MAXN));
status[1 >> 5] = SET(status[1 >> 5], 1 & 31);
for (int i = 3; i <= sqrtN; i = i + 2) {
if (check(status[i >> 5], i & 31) == 0) {
for (int j = i * i; j <= MAXN; j = j + (i << 1)) {
status[j >> 5] = SET(status[j >> 5], j & 31);
}
}
}
primelist.push_back(2);
for (int i = 3; i <= MAXN; i = i + 2) {
if (check(status[i >> 5], i & 31) == 0) {
primelist.push_back(i);
}
}
}
int main() {
int t, hh, mm;
scanf("%d", &t);
scanf("%d:%d", &hh, &mm);
if (t == 24) {
if (hh < 24) {
if (hh < 10) {
printf("0%d:", hh);
} else {
printf("%d:", hh);
}
} else {
printf("0%d:", hh % 10);
}
if (mm < 60) {
if (mm < 10) {
printf("0%d", mm);
} else {
printf("%d", mm);
}
} else {
printf("0%d", mm % 10);
}
} else {
if (hh == 0) {
printf("01:");
} else if (hh > 12) {
if (hh % 10 == 0) {
printf("10:");
} else {
printf("0%d:", hh % 10);
}
} else {
if (hh < 10)
printf("0%d:", hh);
else
printf("%d:", hh);
}
if (mm < 60) {
if (mm < 10)
printf("0%d", mm);
else
printf("%d", mm);
} else {
printf("0%d", mm % 10);
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int MX = 2 * 1e5 + 10;
const double PI = acos(-1.0), EPS = 1e-9;
int N, s;
int arr[MX];
int main() {
cin >> N;
string s;
cin >> s;
if (N == 12) {
int f = s[0] - '0', ss = s[1] - '0';
if (f == 0 && ss == 0) {
s[0] = '1';
} else if (f == 1) {
if (ss > 2) s[1] = '0';
} else if (f > 1) {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
f = s[3] - '0', ss = s[4] - '0';
if (f > 5) s[3] = '1';
} else {
int f = s[0] - '0', ss = s[1] - '0';
if (f == 2) {
if (ss > 3) s[1] = '0';
} else if (f > 2) {
s[0] = '1';
}
f = s[3] - '0', ss = s[4] - '0';
if (f > 5) s[3] = '1';
}
cout << s << "\n";
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MX = 2 * 1e5 + 10;
const double PI = acos(-1.0), EPS = 1e-9;
int N, s;
int arr[MX];
int main() {
cin >> N;
string s;
cin >> s;
if (N == 12) {
int f = s[0] - '0', ss = s[1] - '0';
if (f == 0 && ss == 0) {
s[0] = '1';
} else if (f == 1) {
if (ss > 2) s[1] = '0';
} else if (f > 1) {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
f = s[3] - '0', ss = s[4] - '0';
if (f > 5) s[3] = '1';
} else {
int f = s[0] - '0', ss = s[1] - '0';
if (f == 2) {
if (ss > 3) s[1] = '0';
} else if (f > 2) {
s[0] = '1';
}
f = s[3] - '0', ss = s[4] - '0';
if (f > 5) s[3] = '1';
}
cout << s << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int h, m, t;
char f;
cin >> t;
cin >> h >> f >> m;
if (t == 24) {
int a = h / 10 % 10;
int b = h % 10;
if (a > 2) a = 1;
if (a == 2 && b >= 4) b = 1;
h = 10 * a + b;
a = m / 10 % 10;
b = m % 10;
if (m > 59) a = 1;
m = a * 10 + b;
} else {
int a = h / 10 % 10;
int b = h % 10;
if (a == 1 && b > 2)
a = 0;
else if (a == 0 && b == 0)
b = 1;
else if (a > 1 && b != 0)
a = 0;
else if (a > 1 && b == 0) {
a = 1;
}
h = a * 10 + b;
a = m / 10 % 10;
b = m % 10;
if (m > 59) a = 1;
m = a * 10 + b;
}
if (h == 0)
cout << "00";
else if (h < 10)
cout << "0" << h;
else
cout << h;
cout << ":";
if (m == 0)
cout << "00";
else if (m < 10)
cout << "0" << m;
else
cout << m;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int h, m, t;
char f;
cin >> t;
cin >> h >> f >> m;
if (t == 24) {
int a = h / 10 % 10;
int b = h % 10;
if (a > 2) a = 1;
if (a == 2 && b >= 4) b = 1;
h = 10 * a + b;
a = m / 10 % 10;
b = m % 10;
if (m > 59) a = 1;
m = a * 10 + b;
} else {
int a = h / 10 % 10;
int b = h % 10;
if (a == 1 && b > 2)
a = 0;
else if (a == 0 && b == 0)
b = 1;
else if (a > 1 && b != 0)
a = 0;
else if (a > 1 && b == 0) {
a = 1;
}
h = a * 10 + b;
a = m / 10 % 10;
b = m % 10;
if (m > 59) a = 1;
m = a * 10 + b;
}
if (h == 0)
cout << "00";
else if (h < 10)
cout << "0" << h;
else
cout << h;
cout << ":";
if (m == 0)
cout << "00";
else if (m < 10)
cout << "0" << m;
else
cout << m;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int c, a, b;
scanf("%d", &c);
scanf("%02d:%02d", &a, &b);
if (b >= 60) b %= 10;
if (a > c || a == 24) {
a %= 10;
}
if (c == 12 && a == 0) a = 10;
printf("%02d:%02d", a, b);
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int c, a, b;
scanf("%d", &c);
scanf("%02d:%02d", &a, &b);
if (b >= 60) b %= 10;
if (a > c || a == 24) {
a %= 10;
}
if (c == 12 && a == 0) a = 10;
printf("%02d:%02d", a, b);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, p, q, i, k;
char me[6], me1[6];
scanf("%d", &a);
scanf("%s", me);
if (a == 12) {
p = 0;
i = 0;
p = (p * 10) + (me[0] - '0');
p = (p * 10) + (me[1] - '0');
if (!p) {
me1[i++] = me[0];
me1[i++] = 1 + '0';
} else if (p > 12) {
if (me[1] == '0') {
me1[i++] = 1 + '0';
me1[i++] = 0 + '0';
} else if (me[1] != 0) {
me1[i++] = 0 + '0';
me1[i++] = me[1];
}
} else {
me1[i++] = me[0];
me1[i++] = me[1];
}
} else {
p = 0;
i = 0;
p = (p * 10) + (me[0] - '0');
p = (p * 10) + (me[1] - '0');
if (!p) {
me1[i++] = me[0];
me1[i++] = 0 + '0';
} else if (p > 23) {
if (me[1] == '0') {
me1[i++] = 1 + '0';
me1[i++] = 0 + '0';
} else if (me[1] != 0) {
me1[i++] = 0 + '0';
me1[i++] = me[1];
}
} else {
me1[i++] = me[0];
me1[i++] = me[1];
}
}
me1[i++] = ':';
a = 0;
a = (a * 10) + (me[3] - '0');
a = (a * 10) + (me[4] - '0');
if (a > 59) {
if (me[4] != 0) {
me1[i++] = 0 + '0';
me1[i++] = me[4];
} else {
me1[i++] = 0 + '0';
me1[i++] = 1 + '0';
}
} else {
me1[i++] = me[3];
me1[i++] = me[4];
}
for (i = 0; i < 5; i++) {
printf("%c", me1[i]);
}
cout << endl;
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, p, q, i, k;
char me[6], me1[6];
scanf("%d", &a);
scanf("%s", me);
if (a == 12) {
p = 0;
i = 0;
p = (p * 10) + (me[0] - '0');
p = (p * 10) + (me[1] - '0');
if (!p) {
me1[i++] = me[0];
me1[i++] = 1 + '0';
} else if (p > 12) {
if (me[1] == '0') {
me1[i++] = 1 + '0';
me1[i++] = 0 + '0';
} else if (me[1] != 0) {
me1[i++] = 0 + '0';
me1[i++] = me[1];
}
} else {
me1[i++] = me[0];
me1[i++] = me[1];
}
} else {
p = 0;
i = 0;
p = (p * 10) + (me[0] - '0');
p = (p * 10) + (me[1] - '0');
if (!p) {
me1[i++] = me[0];
me1[i++] = 0 + '0';
} else if (p > 23) {
if (me[1] == '0') {
me1[i++] = 1 + '0';
me1[i++] = 0 + '0';
} else if (me[1] != 0) {
me1[i++] = 0 + '0';
me1[i++] = me[1];
}
} else {
me1[i++] = me[0];
me1[i++] = me[1];
}
}
me1[i++] = ':';
a = 0;
a = (a * 10) + (me[3] - '0');
a = (a * 10) + (me[4] - '0');
if (a > 59) {
if (me[4] != 0) {
me1[i++] = 0 + '0';
me1[i++] = me[4];
} else {
me1[i++] = 0 + '0';
me1[i++] = 1 + '0';
}
} else {
me1[i++] = me[3];
me1[i++] = me[4];
}
for (i = 0; i < 5; i++) {
printf("%c", me1[i]);
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long format;
cin >> format;
string str;
cin >> str;
if (format == 12) {
if (str[0] != '0' && str[0] != '1') {
if (str[1] == '0') {
str[0] = '1';
} else {
str[0] = '0';
}
}
if (str[0] == '0') {
if (str[1] == '0') {
str[1] = '1';
}
}
if (str[0] == '1') {
if (str[1] != '0' && str[1] != '1' && str[1] != '2') {
str[1] = '1';
}
}
if (str[3] - '0' > 5) {
str[3] = '5';
}
} else {
if (str[0] - '0' > 2) {
str[0] = '1';
}
if (str[0] == '2' && str[1] - '0' > 3) {
str[1] = '1';
}
if (str[3] - '0' > 5) {
str[3] = '5';
}
}
cout << str;
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long format;
cin >> format;
string str;
cin >> str;
if (format == 12) {
if (str[0] != '0' && str[0] != '1') {
if (str[1] == '0') {
str[0] = '1';
} else {
str[0] = '0';
}
}
if (str[0] == '0') {
if (str[1] == '0') {
str[1] = '1';
}
}
if (str[0] == '1') {
if (str[1] != '0' && str[1] != '1' && str[1] != '2') {
str[1] = '1';
}
}
if (str[3] - '0' > 5) {
str[3] = '5';
}
} else {
if (str[0] - '0' > 2) {
str[0] = '1';
}
if (str[0] == '2' && str[1] - '0' > 3) {
str[1] = '1';
}
if (str[3] - '0' > 5) {
str[3] = '5';
}
}
cout << str;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, m;
char c;
cin >> n;
cin >> h >> c >> m;
if (n == 24) {
if (h < 0) h = 00;
if (h > 23) h %= 10;
if (m > 59) m %= 10;
}
if (n == 12) {
if (h < 1) h = 01;
if (h > 12) {
if (h % 10 != 0) h %= 10;
if (h % 10 == 0) h = 10;
}
if (m > 59) m %= 10;
}
if (h < 10 && m >= 10)
cout << "0" << h << ":" << m << endl;
else if (h >= 10 && m < 10)
cout << h << ":"
<< "0" << m << endl;
else if (h < 10 && m < 10)
cout << "0" << h << ":"
<< "0" << m << endl;
else
cout << h << ":" << m;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, m;
char c;
cin >> n;
cin >> h >> c >> m;
if (n == 24) {
if (h < 0) h = 00;
if (h > 23) h %= 10;
if (m > 59) m %= 10;
}
if (n == 12) {
if (h < 1) h = 01;
if (h > 12) {
if (h % 10 != 0) h %= 10;
if (h % 10 == 0) h = 10;
}
if (m > 59) m %= 10;
}
if (h < 10 && m >= 10)
cout << "0" << h << ":" << m << endl;
else if (h >= 10 && m < 10)
cout << h << ":"
<< "0" << m << endl;
else if (h < 10 && m < 10)
cout << "0" << h << ":"
<< "0" << m << endl;
else
cout << h << ":" << m;
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int m;
char s[100];
int hour = 0, min = 0;
scanf("%d", &m);
scanf("%s", s);
hour = 10 * (s[0] - '0') + s[1] - '0';
min = 10 * (s[3] - '0') + s[4] - '0';
if (m == 24) {
if (hour > 23) hour %= 10;
if (min > 59) min %= 10;
} else {
if (hour > 12 && hour % 10 != 0) hour %= 10;
if (hour > 12 && hour % 10 == 0) hour = 10;
if (hour == 0) hour = 1;
if (min > 59) min %= 10;
}
if (hour < 10)
printf("0%d", hour);
else
printf("%d", hour);
printf(":");
if (min < 10)
printf("0%d", min);
else
printf("%d", min);
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int m;
char s[100];
int hour = 0, min = 0;
scanf("%d", &m);
scanf("%s", s);
hour = 10 * (s[0] - '0') + s[1] - '0';
min = 10 * (s[3] - '0') + s[4] - '0';
if (m == 24) {
if (hour > 23) hour %= 10;
if (min > 59) min %= 10;
} else {
if (hour > 12 && hour % 10 != 0) hour %= 10;
if (hour > 12 && hour % 10 == 0) hour = 10;
if (hour == 0) hour = 1;
if (min > 59) min %= 10;
}
if (hour < 10)
printf("0%d", hour);
else
printf("%d", hour);
printf(":");
if (min < 10)
printf("0%d", min);
else
printf("%d", min);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int typ, hh, mm;
int main() {
cin >> typ >> hh;
cin.ignore();
cin >> mm;
if (mm / 10 > 5) mm = 50 + mm % 10;
if (typ == 12 && !hh) hh = 1;
if (typ == 12 && hh > 12) {
if (hh % 10)
hh = hh % 10;
else
hh = 10;
}
if (typ == 24 && hh > 23) hh = hh % 10 + 10;
printf("%02d:%02d", hh, mm);
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int typ, hh, mm;
int main() {
cin >> typ >> hh;
cin.ignore();
cin >> mm;
if (mm / 10 > 5) mm = 50 + mm % 10;
if (typ == 12 && !hh) hh = 1;
if (typ == 12 && hh > 12) {
if (hh % 10)
hh = hh % 10;
else
hh = 10;
}
if (typ == 24 && hh > 23) hh = hh % 10 + 10;
printf("%02d:%02d", hh, mm);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
string n;
cin >> n;
string str;
cin >> str;
if (n == "12") {
if (str.substr(0, 2) == "00") {
str[1] = '1';
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
}
if (str.substr(0, 2) <= n) {
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
} else {
if (str[1] == '0')
str[0] = '1';
else
str[0] = '0';
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
}
}
if (str.substr(0, 2) < n) {
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
} else {
str[0] = '0';
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
string n;
cin >> n;
string str;
cin >> str;
if (n == "12") {
if (str.substr(0, 2) == "00") {
str[1] = '1';
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
}
if (str.substr(0, 2) <= n) {
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
} else {
if (str[1] == '0')
str[0] = '1';
else
str[0] = '0';
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
}
}
if (str.substr(0, 2) < n) {
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
} else {
str[0] = '0';
if (str.substr(3, 2) <= "59") {
cout << str << endl;
return 0;
} else {
str[3] = '0';
cout << str << endl;
return 0;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char foo[10];
int main() {
int x;
scanf("%d", &x);
int h, m;
scanf("%d:%d", &h, &m);
if (x == 12) {
if (h == 0)
h++;
else if (h > 12) {
while (h > 12) h -= 10;
}
} else {
if (h > 23) {
while (h > 23) h -= 10;
}
}
while (m >= 60) m -= 10;
printf("%02d:%02d\n", h, m);
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char foo[10];
int main() {
int x;
scanf("%d", &x);
int h, m;
scanf("%d:%d", &h, &m);
if (x == 12) {
if (h == 0)
h++;
else if (h > 12) {
while (h > 12) h -= 10;
}
} else {
if (h > 23) {
while (h > 23) h -= 10;
}
}
while (m >= 60) m -= 10;
printf("%02d:%02d\n", h, m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h1, h2, m1, m2;
cin >> h1;
char c;
cin >> c;
cin >> m1;
if (m1 > 59) {
m1 = m1 % 10;
}
if (n == 12) {
if (h1 > 12) {
h1 = h1 % 10;
}
}
if (n == 24) {
if (h1 >= 24) {
h1 = h1 % 10;
}
}
if (h1 > 9) cout << h1;
if (h1 <= 9) {
if (h1 == 0 && n == 12)
cout << 10;
else
cout << 0 << h1;
}
if (m1 > 9) cout << ":" << m1 << endl;
if (m1 <= 9) {
cout << ":" << 0 << m1 << endl;
}
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h1, h2, m1, m2;
cin >> h1;
char c;
cin >> c;
cin >> m1;
if (m1 > 59) {
m1 = m1 % 10;
}
if (n == 12) {
if (h1 > 12) {
h1 = h1 % 10;
}
}
if (n == 24) {
if (h1 >= 24) {
h1 = h1 % 10;
}
}
if (h1 > 9) cout << h1;
if (h1 <= 9) {
if (h1 == 0 && n == 12)
cout << 10;
else
cout << 0 << h1;
}
if (m1 > 9) cout << ":" << m1 << endl;
if (m1 <= 9) {
cout << ":" << 0 << m1 << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (n == 12) {
if ((s[0] > '1') && (s[1] != '0'))
s[0] = '0';
else if (s[0] > '1' && s[1] == '0')
s[0] = '1';
else if (s[0] == '1' && s[1] > '2')
s[0] = '0';
else if (s[0] == '0' && s[1] == '0')
s[1] = '1';
if (s[3] >= '6') s[3] = '0';
} else if (n == 24) {
if (s[0] > '2')
s[0] = '1';
else if (s[0] == '2' && s[1] > '3')
s[0] = '0';
if (s[3] >= '6') s[3] = '0';
}
cout << s << endl;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (n == 12) {
if ((s[0] > '1') && (s[1] != '0'))
s[0] = '0';
else if (s[0] > '1' && s[1] == '0')
s[0] = '1';
else if (s[0] == '1' && s[1] > '2')
s[0] = '0';
else if (s[0] == '0' && s[1] == '0')
s[1] = '1';
if (s[3] >= '6') s[3] = '0';
} else if (n == 24) {
if (s[0] > '2')
s[0] = '1';
else if (s[0] == '2' && s[1] > '3')
s[0] = '0';
if (s[3] >= '6') s[3] = '0';
}
cout << s << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int f, g;
string s;
cin >> f >> s;
int hours = (s[0] - '0') * 10 + (s[1] - '0'),
minutes = (s[3] - '0') * 10 + (s[4] - '0');
if (minutes > 59) minutes %= 10;
if (f == 12) {
if (hours == 0)
hours = 1;
else if (hours > 12) {
if (hours % 10 != 0)
hours %= 10;
else
hours = 10;
}
} else {
if (hours > 23) hours %= 10;
}
if (hours < 10)
cout << 0 << hours << ':';
else
cout << hours << ':';
if (minutes < 10)
cout << 0 << minutes;
else
cout << minutes;
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int f, g;
string s;
cin >> f >> s;
int hours = (s[0] - '0') * 10 + (s[1] - '0'),
minutes = (s[3] - '0') * 10 + (s[4] - '0');
if (minutes > 59) minutes %= 10;
if (f == 12) {
if (hours == 0)
hours = 1;
else if (hours > 12) {
if (hours % 10 != 0)
hours %= 10;
else
hours = 10;
}
} else {
if (hours > 23) hours %= 10;
}
if (hours < 10)
cout << 0 << hours << ':';
else
cout << hours << ':';
if (minutes < 10)
cout << 0 << minutes;
else
cout << minutes;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
char h1, h0, del, m1, m0;
cin >> h1 >> h0 >> del >> m1 >> m0;
if (m1 > '5') {
m1 = '0';
}
if (n == 12 && h1 == '1' && h0 > '2') {
h0 = '0';
}
if (h1 > '2' || (h1 == '2' && (h0 > '3' || n == 12))) {
if (h0 != '0' || n != 12) {
h1 = '0';
} else {
h1 = '1';
}
}
if (n == 12 && h1 == '0' && h0 == '0') {
h0 = '1';
}
cout << h1 << h0 << del << m1 << m0 << '\n';
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
char h1, h0, del, m1, m0;
cin >> h1 >> h0 >> del >> m1 >> m0;
if (m1 > '5') {
m1 = '0';
}
if (n == 12 && h1 == '1' && h0 > '2') {
h0 = '0';
}
if (h1 > '2' || (h1 == '2' && (h0 > '3' || n == 12))) {
if (h0 != '0' || n != 12) {
h1 = '0';
} else {
h1 = '1';
}
}
if (n == 12 && h1 == '0' && h0 == '0') {
h0 = '1';
}
cout << h1 << h0 << del << m1 << m0 << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double epos = 1e-8;
const int maxn = 200009;
char s[maxn];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s);
int hour = (s[0] - '0') * 10 + s[1] - '0';
int m = (s[3] - '0') * 10 + s[4] - '0';
if (n == 12) {
if (hour == 12) {
if (m >= 60) {
s[3] = '0';
}
} else if (hour < 12) {
if (hour == 0) s[1] = '1';
if (m >= 60) s[3] = '0';
} else {
if (s[1] - '0')
s[0] = '0';
else
s[0] = '1';
if (m >= 60) s[3] = '0';
}
} else {
if (hour == 23) {
if (m >= 60) {
s[3] = '0';
}
} else if (hour < 23) {
if (m >= 60) s[3] = '0';
} else {
s[0] = '0';
if (m >= 60) s[3] = '0';
}
}
printf("%s\n", s);
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double epos = 1e-8;
const int maxn = 200009;
char s[maxn];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s);
int hour = (s[0] - '0') * 10 + s[1] - '0';
int m = (s[3] - '0') * 10 + s[4] - '0';
if (n == 12) {
if (hour == 12) {
if (m >= 60) {
s[3] = '0';
}
} else if (hour < 12) {
if (hour == 0) s[1] = '1';
if (m >= 60) s[3] = '0';
} else {
if (s[1] - '0')
s[0] = '0';
else
s[0] = '1';
if (m >= 60) s[3] = '0';
}
} else {
if (hour == 23) {
if (m >= 60) {
s[3] = '0';
}
} else if (hour < 23) {
if (m >= 60) s[3] = '0';
} else {
s[0] = '0';
if (m >= 60) s[3] = '0';
}
}
printf("%s\n", s);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
int a, b;
char x;
cin >> a >> x >> b;
if (n == 12) {
if (0 < a && a < 13) {
} else if (a == 0) {
a = 10;
} else if (a < 20) {
a = 10;
} else if (a % 10 == 0) {
a = 10;
} else
a = a % 10;
} else {
if (a > 23) {
a = 10 + a % 10;
}
}
if (b >= 60) {
b = 10 + b % 10;
}
if (a < 10) {
cout << 0;
}
cout << a << ':';
if (b < 10) {
cout << 0;
}
cout << b;
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
int a, b;
char x;
cin >> a >> x >> b;
if (n == 12) {
if (0 < a && a < 13) {
} else if (a == 0) {
a = 10;
} else if (a < 20) {
a = 10;
} else if (a % 10 == 0) {
a = 10;
} else
a = a % 10;
} else {
if (a > 23) {
a = 10 + a % 10;
}
}
if (b >= 60) {
b = 10 + b % 10;
}
if (a < 10) {
cout << 0;
}
cout << a << ':';
if (b < 10) {
cout << 0;
}
cout << b;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int diff(string a, string b) {
if (a == b) return 0;
if (a[0] == b[0] || a[1] == b[1]) return 1;
return 2;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int format;
cin >> format;
string time;
cin >> time;
string h, m;
h = time[0];
h = h + time[1];
m = time[3];
m = m + time[4];
string arr[12] = {"01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12"};
string arr2[24] = {"00", "01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23"};
string ans;
if (format == 12) {
string temp;
int wawa = 3;
for (int i = 0; i < 12; i++) {
if (diff(h, arr[i]) < wawa) {
wawa = diff(h, arr[i]);
temp = arr[i];
}
}
ans = temp;
if (m[0] != '0' && m[0] != '1' && m[0] != '2' && m[0] != '3' &&
m[0] != '4' && m[0] != '5')
m[0] = '1';
ans = ans + ':';
ans = ans + m;
} else {
string temp;
int wawa = 3;
for (int i = 0; i < 24; i++) {
if (diff(h, arr2[i]) < wawa) {
wawa = diff(h, arr2[i]);
temp = arr2[i];
}
}
ans = temp;
if (m[0] != '0' && m[0] != '1' && m[0] != '2' && m[0] != '3' &&
m[0] != '4' && m[0] != '5')
m[0] = '1';
ans = ans + ':';
ans = ans + m;
}
cout << ans;
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int diff(string a, string b) {
if (a == b) return 0;
if (a[0] == b[0] || a[1] == b[1]) return 1;
return 2;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int format;
cin >> format;
string time;
cin >> time;
string h, m;
h = time[0];
h = h + time[1];
m = time[3];
m = m + time[4];
string arr[12] = {"01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12"};
string arr2[24] = {"00", "01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23"};
string ans;
if (format == 12) {
string temp;
int wawa = 3;
for (int i = 0; i < 12; i++) {
if (diff(h, arr[i]) < wawa) {
wawa = diff(h, arr[i]);
temp = arr[i];
}
}
ans = temp;
if (m[0] != '0' && m[0] != '1' && m[0] != '2' && m[0] != '3' &&
m[0] != '4' && m[0] != '5')
m[0] = '1';
ans = ans + ':';
ans = ans + m;
} else {
string temp;
int wawa = 3;
for (int i = 0; i < 24; i++) {
if (diff(h, arr2[i]) < wawa) {
wawa = diff(h, arr2[i]);
temp = arr2[i];
}
}
ans = temp;
if (m[0] != '0' && m[0] != '1' && m[0] != '2' && m[0] != '3' &&
m[0] != '4' && m[0] != '5')
m[0] = '1';
ans = ans + ':';
ans = ans + m;
}
cout << ans;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, h;
string s;
cin >> n >> s;
m = (s[3] - '0') * 10 + s[4] - '0';
if (m > 59) {
s[3] = '0';
}
if (n == 24) {
h = (s[0] - '0') * 10 + s[1] - '0';
if (h > 23) {
if (s[0] - '0' > 2)
s[0] = '0';
else if (s[1] - '0' > 3)
s[1] = '0';
}
} else {
h = (s[0] - '0') * 10 + s[1] - '0';
if (h == 0) s[1] = '1';
if (h > 12) {
if (s[0] - '0' > 1)
s[0] = '0';
else if (s[1] - '0' > 2)
s[1] = '2';
if (s[0] == '0' && s[1] == '0') s[0] = '1';
}
}
cout << s << endl;
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, h;
string s;
cin >> n >> s;
m = (s[3] - '0') * 10 + s[4] - '0';
if (m > 59) {
s[3] = '0';
}
if (n == 24) {
h = (s[0] - '0') * 10 + s[1] - '0';
if (h > 23) {
if (s[0] - '0' > 2)
s[0] = '0';
else if (s[1] - '0' > 3)
s[1] = '0';
}
} else {
h = (s[0] - '0') * 10 + s[1] - '0';
if (h == 0) s[1] = '1';
if (h > 12) {
if (s[0] - '0' > 1)
s[0] = '0';
else if (s[1] - '0' > 2)
s[1] = '2';
if (s[0] == '0' && s[1] == '0') s[0] = '1';
}
}
cout << s << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (n == 24) {
if (s[0] >= '0' && s[0] <= '2') {
if (s[1] >= '4' && s[0] == '2') {
s[0] = '0';
}
} else {
s[0] = '0';
}
if (!(s[3] >= '0' && s[3] <= '5')) {
s[3] = '0';
}
} else {
if (s[0] >= '1') {
if (s[0] > '1' && s[1] == '0') {
s[0] = '1';
}
if (s[0] > '1') {
s[0] = '0';
}
if (s[1] > '2' && s[0] > '0') {
s[1] = '0';
}
} else if (s[0] == '0' && s[1] == '0') {
s[1] = '1';
}
if (!(s[3] >= '0' && s[3] <= '5')) {
s[3] = '0';
}
}
cout << s;
}
|
### Prompt
In CPP, your task is to solve the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (n == 24) {
if (s[0] >= '0' && s[0] <= '2') {
if (s[1] >= '4' && s[0] == '2') {
s[0] = '0';
}
} else {
s[0] = '0';
}
if (!(s[3] >= '0' && s[3] <= '5')) {
s[3] = '0';
}
} else {
if (s[0] >= '1') {
if (s[0] > '1' && s[1] == '0') {
s[0] = '1';
}
if (s[0] > '1') {
s[0] = '0';
}
if (s[1] > '2' && s[0] > '0') {
s[1] = '0';
}
} else if (s[0] == '0' && s[1] == '0') {
s[1] = '1';
}
if (!(s[3] >= '0' && s[3] <= '5')) {
s[3] = '0';
}
}
cout << s;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int INF = INT_MAX;
const int MAX_N = 50005;
template <typename T>
inline T sqr(T a) {
return a * a;
};
int n, h, m;
int main(int argc, char const *argv[]) {
scanf("%d", &n);
scanf("%d:%d", &h, &m);
if (n == 24) {
if (h > 23) h = h % 10;
if (m >= 60) m = m % 10;
} else {
if (h == 0)
h = 1;
else if (h > 12) {
if (h % 10 != 0)
h = h % 10;
else
h = 10;
}
if (m >= 60) m = m % 10;
}
printf("%02d:%02d\n", h, m);
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int INF = INT_MAX;
const int MAX_N = 50005;
template <typename T>
inline T sqr(T a) {
return a * a;
};
int n, h, m;
int main(int argc, char const *argv[]) {
scanf("%d", &n);
scanf("%d:%d", &h, &m);
if (n == 24) {
if (h > 23) h = h % 10;
if (m >= 60) m = m % 10;
} else {
if (h == 0)
h = 1;
else if (h > 12) {
if (h % 10 != 0)
h = h % 10;
else
h = 10;
}
if (m >= 60) m = m % 10;
}
printf("%02d:%02d\n", h, m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int change(int a) {
if (a >= 0 && a <= 59)
return a;
else {
return a % 10;
}
}
int change24(int a) {
if (a >= 0 && a <= 23)
return a;
else
return a % 10;
}
int change12(int a) {
if (a >= 1 && a <= 12)
return a;
else {
if (a % 10 == 0) {
return 10;
} else
return a % 10;
}
}
int main() {
string time;
int a, t1, t2;
cin >> a;
int t;
int i = 0;
if (a == 12) {
cin >> time;
t = (time[i] - '0') * 10 + (time[i + 1] - '0');
t2 = (time[i + 3] - '0') * 10 + (time[i + 4] - '0');
t = change12(t);
t2 = change(t2);
time[i] = (t / 10) + '0';
time[i + 1] = (t % 10) + '0';
time[i + 3] = (t2 / 10) + '0';
time[i + 4] = (t2 % 10) + '0';
cout << time << endl;
} else {
cin >> time;
t = (time[i] - '0') * 10 + (time[i + 1] - '0');
t2 = (time[i + 3] - '0') * 10 + (time[i + 4] - '0');
t = change24(t);
t2 = change(t2);
time[i] = (t / 10) + '0';
time[i + 1] = (t % 10) + '0';
time[i + 3] = (t2 / 10) + '0';
time[i + 4] = (t2 % 10) + '0';
cout << time << endl;
}
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int change(int a) {
if (a >= 0 && a <= 59)
return a;
else {
return a % 10;
}
}
int change24(int a) {
if (a >= 0 && a <= 23)
return a;
else
return a % 10;
}
int change12(int a) {
if (a >= 1 && a <= 12)
return a;
else {
if (a % 10 == 0) {
return 10;
} else
return a % 10;
}
}
int main() {
string time;
int a, t1, t2;
cin >> a;
int t;
int i = 0;
if (a == 12) {
cin >> time;
t = (time[i] - '0') * 10 + (time[i + 1] - '0');
t2 = (time[i + 3] - '0') * 10 + (time[i + 4] - '0');
t = change12(t);
t2 = change(t2);
time[i] = (t / 10) + '0';
time[i + 1] = (t % 10) + '0';
time[i + 3] = (t2 / 10) + '0';
time[i + 4] = (t2 % 10) + '0';
cout << time << endl;
} else {
cin >> time;
t = (time[i] - '0') * 10 + (time[i + 1] - '0');
t2 = (time[i + 3] - '0') * 10 + (time[i + 4] - '0');
t = change24(t);
t2 = change(t2);
time[i] = (t / 10) + '0';
time[i + 1] = (t % 10) + '0';
time[i + 3] = (t2 / 10) + '0';
time[i + 4] = (t2 % 10) + '0';
cout << time << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int a = s[0] - 48, b = s[1] - 48, c = s[3] - 48, d = s[4] - 48;
int x = 10 * a + b, y = 10 * c + d;
if (n == 12) {
if (x > 12) {
if (b == 0) {
a = 1;
} else
a = 0;
} else if (x == 0)
b = 1;
if (y > 59) {
if (d == 0)
c = 1;
else
c = 0;
}
} else if (n == 24) {
if (x > 23) {
if (b == 0) {
a = 1;
} else
a = 0;
}
if (y > 59) {
if (d == 0)
c = 1;
else
c = 0;
}
}
cout << a << b << ':' << c << d;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int a = s[0] - 48, b = s[1] - 48, c = s[3] - 48, d = s[4] - 48;
int x = 10 * a + b, y = 10 * c + d;
if (n == 12) {
if (x > 12) {
if (b == 0) {
a = 1;
} else
a = 0;
} else if (x == 0)
b = 1;
if (y > 59) {
if (d == 0)
c = 1;
else
c = 0;
}
} else if (n == 24) {
if (x > 23) {
if (b == 0) {
a = 1;
} else
a = 0;
}
if (y > 59) {
if (d == 0)
c = 1;
else
c = 0;
}
}
cout << a << b << ':' << c << d;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
while (~scanf("%d", &a)) {
int flag1, flag2;
flag1 = flag2 = 0;
scanf("%d:%d", &b, &c);
if (a == 12) {
if (b > 12 || b == 0) {
b %= 10;
if (b == 0) {
b = 10;
} else
flag1 = 1;
} else if (b < 10)
flag1 = 1;
if (c > 59) {
c %= 10;
flag2 = 1;
} else if (c < 10)
flag2 = 1;
} else {
if (b > 23) {
b %= 10;
if (b == 0) {
b = 10;
} else
flag1 = 1;
} else if (b < 10)
flag1 = 1;
if (c > 59) {
c %= 10;
flag2 = 1;
} else if (c < 10)
flag2 = 1;
}
if (flag1 == 0 && flag2 == 0)
printf("%d:%d\n", b, c);
else if (flag2 == 0)
printf("0%d:%d\n", b, c);
else if (flag1 == 0)
printf("%d:0%d\n", b, c);
else
printf("0%d:0%d\n", b, c);
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
while (~scanf("%d", &a)) {
int flag1, flag2;
flag1 = flag2 = 0;
scanf("%d:%d", &b, &c);
if (a == 12) {
if (b > 12 || b == 0) {
b %= 10;
if (b == 0) {
b = 10;
} else
flag1 = 1;
} else if (b < 10)
flag1 = 1;
if (c > 59) {
c %= 10;
flag2 = 1;
} else if (c < 10)
flag2 = 1;
} else {
if (b > 23) {
b %= 10;
if (b == 0) {
b = 10;
} else
flag1 = 1;
} else if (b < 10)
flag1 = 1;
if (c > 59) {
c %= 10;
flag2 = 1;
} else if (c < 10)
flag2 = 1;
}
if (flag1 == 0 && flag2 == 0)
printf("%d:%d\n", b, c);
else if (flag2 == 0)
printf("0%d:%d\n", b, c);
else if (flag1 == 0)
printf("%d:0%d\n", b, c);
else
printf("0%d:0%d\n", b, c);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int format;
string s;
cin >> format >> s;
if (format == 12) {
if (s[0] == '0')
if (s[1] == '0') s[1] = '2';
if (s[1] > '2')
if (s[0] > '0') s[0] = '0';
if (s[3] > '5') s[3] = '0';
if (s[0] > '1') {
if (s[1] < '3')
s[0] = '1';
else {
s[0] = '1';
s[1] = '1';
}
}
cout << s;
} else {
if (s[0] > '1') {
s[0] = '2';
if (s[1] > '3') s[0] = '1';
}
if (s[0] > '2') s[0] = '1';
if (s[3] > '5') s[3] = '0';
cout << s;
}
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int format;
string s;
cin >> format >> s;
if (format == 12) {
if (s[0] == '0')
if (s[1] == '0') s[1] = '2';
if (s[1] > '2')
if (s[0] > '0') s[0] = '0';
if (s[3] > '5') s[3] = '0';
if (s[0] > '1') {
if (s[1] < '3')
s[0] = '1';
else {
s[0] = '1';
s[1] = '1';
}
}
cout << s;
} else {
if (s[0] > '1') {
s[0] = '2';
if (s[1] > '3') s[0] = '1';
}
if (s[0] > '2') s[0] = '1';
if (s[3] > '5') s[3] = '0';
cout << s;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
void readStrn(char a[], long n) {
for (register long i = 0; i < n; i++) a[i] = getchar();
getchar();
}
void readStr(char a[], long &n) {
n = 0;
for (register char c = getchar(); c >= 'a' && c <= 'z'; c = getchar())
a[n++] = c;
}
long long readLI() {
register char c;
for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
;
register long long a = c - '0';
for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
a = (a << 3) + (a << 1) + c - '0';
return a;
}
int main() {
int type;
cin >> type;
string time;
cin >> time;
if (type == 24) {
if (time[0] - '0' >= 3) time[0] = '0';
if (time[0] == '0' || time[0] == '1') {
if (time[1] - '0' > 9) time[1] = '0';
} else if (time[0] == '2') {
if (time[1] - '0' >= 4) time[1] = '0';
}
} else {
if (time[0] - '0' >= 2 && time[1] == '0')
time[0] = '1';
else if (time[0] - '0' >= 2)
time[0] = '0';
if (time[0] == '0') {
if (time[1] - '0' > 9 || time[1] == '0') time[1] = '1';
} else if (time[0] == '1') {
if (time[1] - '0' >= 3) time[1] = '0';
}
}
if (time[3] - '0' >= 6) time[3] = '0';
cout << time;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
void readStrn(char a[], long n) {
for (register long i = 0; i < n; i++) a[i] = getchar();
getchar();
}
void readStr(char a[], long &n) {
n = 0;
for (register char c = getchar(); c >= 'a' && c <= 'z'; c = getchar())
a[n++] = c;
}
long long readLI() {
register char c;
for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
;
register long long a = c - '0';
for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
a = (a << 3) + (a << 1) + c - '0';
return a;
}
int main() {
int type;
cin >> type;
string time;
cin >> time;
if (type == 24) {
if (time[0] - '0' >= 3) time[0] = '0';
if (time[0] == '0' || time[0] == '1') {
if (time[1] - '0' > 9) time[1] = '0';
} else if (time[0] == '2') {
if (time[1] - '0' >= 4) time[1] = '0';
}
} else {
if (time[0] - '0' >= 2 && time[1] == '0')
time[0] = '1';
else if (time[0] - '0' >= 2)
time[0] = '0';
if (time[0] == '0') {
if (time[1] - '0' > 9 || time[1] == '0') time[1] = '1';
} else if (time[0] == '1') {
if (time[1] - '0' >= 3) time[1] = '0';
}
}
if (time[3] - '0' >= 6) time[3] = '0';
cout << time;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
string s, q = "", p = "";
cin >> s;
int hr = (s[0] - '0') * 10 + (s[1] - '0');
int min = (s[3] - '0') * 10 + (s[4] - '0');
if (!(min >= 0 && min <= 59)) min = 2 * 10 + (s[4] - '0');
if (min >= 0 && min <= 9) {
q = to_string(min);
q = "0" + q;
} else
q = to_string(min);
if (hr >= 0 && hr <= 9 && t == 24) {
p = to_string(hr);
p = "0" + p;
cout << p << ":" << q << endl;
return 0;
}
if (t == 24) {
if (hr >= 10 && hr <= 23)
cout << hr << ":" << q << endl;
else {
hr = 10 + (s[1] - '0');
cout << hr << ":" << q << endl;
}
return 0;
} else {
if (hr == 0)
cout << "10"
<< ":" << q << endl;
else if (hr >= 1 && hr <= 9) {
cout << "0" << hr << ":" << q << endl;
} else if (hr >= 10 && hr <= 12)
cout << hr << ":" << q << endl;
else {
if (s[1] == '0') {
cout << "1" << s[1] << ":" << q << endl;
} else
cout << "0" << s[1] << ":" << q << endl;
}
}
}
|
### Prompt
Generate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
string s, q = "", p = "";
cin >> s;
int hr = (s[0] - '0') * 10 + (s[1] - '0');
int min = (s[3] - '0') * 10 + (s[4] - '0');
if (!(min >= 0 && min <= 59)) min = 2 * 10 + (s[4] - '0');
if (min >= 0 && min <= 9) {
q = to_string(min);
q = "0" + q;
} else
q = to_string(min);
if (hr >= 0 && hr <= 9 && t == 24) {
p = to_string(hr);
p = "0" + p;
cout << p << ":" << q << endl;
return 0;
}
if (t == 24) {
if (hr >= 10 && hr <= 23)
cout << hr << ":" << q << endl;
else {
hr = 10 + (s[1] - '0');
cout << hr << ":" << q << endl;
}
return 0;
} else {
if (hr == 0)
cout << "10"
<< ":" << q << endl;
else if (hr >= 1 && hr <= 9) {
cout << "0" << hr << ":" << q << endl;
} else if (hr >= 10 && hr <= 12)
cout << hr << ":" << q << endl;
else {
if (s[1] == '0') {
cout << "1" << s[1] << ":" << q << endl;
} else
cout << "0" << s[1] << ":" << q << endl;
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
string s;
cin >> s;
if (t == 12) {
if (s.at(0) >= '2') {
if (s.at(1) == '0')
s.at(0) = '1';
else
s.at(0) = '0';
} else if (s.at(0) == '1') {
if (s.at(1) >= '3') s.at(1) = '0';
} else {
if (s.at(0) == '0' && s.at(1) == '0') s.at(1) = '1';
}
} else {
if (s.at(0) >= '3') {
if (s.at(1) == '0')
s.at(0) = '1';
else
s.at(0) = '0';
} else if (s.at(0) == '2') {
if (s.at(1) >= '4') s.at(0) = '1';
}
}
if (s.at(3) >= '6') {
if (s.at(4) == '0')
s.at(3) = '1';
else
s.at(3) = '0';
}
cout << s;
}
|
### Prompt
Create a solution in cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
string s;
cin >> s;
if (t == 12) {
if (s.at(0) >= '2') {
if (s.at(1) == '0')
s.at(0) = '1';
else
s.at(0) = '0';
} else if (s.at(0) == '1') {
if (s.at(1) >= '3') s.at(1) = '0';
} else {
if (s.at(0) == '0' && s.at(1) == '0') s.at(1) = '1';
}
} else {
if (s.at(0) >= '3') {
if (s.at(1) == '0')
s.at(0) = '1';
else
s.at(0) = '0';
} else if (s.at(0) == '2') {
if (s.at(1) >= '4') s.at(0) = '1';
}
}
if (s.at(3) >= '6') {
if (s.at(4) == '0')
s.at(3) = '1';
else
s.at(3) = '0';
}
cout << s;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char arr[5];
int main() {
int n;
cin >> n;
string s;
cin >> s;
int min = (s[3] - '0') * 10 + (s[4] - '0');
if (min > 59) {
s[3] = s[3] - '6' + '0';
}
int l = (s[0] - '0') * 10 + (s[1] - '0');
if (n == 24) {
if (l > 23) {
s[0] = '0';
}
} else {
if (l > 12 || l == 0) {
if (l == 0)
s[0] = '1';
else {
if (s[0] > '1' && s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
}
}
cout << s << endl;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char arr[5];
int main() {
int n;
cin >> n;
string s;
cin >> s;
int min = (s[3] - '0') * 10 + (s[4] - '0');
if (min > 59) {
s[3] = s[3] - '6' + '0';
}
int l = (s[0] - '0') * 10 + (s[1] - '0');
if (n == 24) {
if (l > 23) {
s[0] = '0';
}
} else {
if (l > 12 || l == 0) {
if (l == 0)
s[0] = '1';
else {
if (s[0] > '1' && s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
}
}
cout << s << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int clockFormat;
cin >> clockFormat;
char dummy;
int h, m;
cin >> h >> dummy >> m;
if (clockFormat == 12) {
if (h >= 1 && h <= 12) {
if (h < 10) cout << 0;
cout << h;
} else if (h == 0)
cout << "01";
else if (h % 10)
cout << 0 << h % 10;
else
cout << "10";
} else {
if (h >= 1 && h <= 23) {
if (h < 10) cout << 0;
cout << h;
} else if (h == 0)
cout << "00";
else
cout << 1 << h % 10;
}
cout << ':';
if (m >= 0 && m <= 59) {
if (m < 10) cout << 0;
cout << m;
} else
cout << 1 << m % 10;
}
|
### Prompt
Please create a solution in CPP to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int clockFormat;
cin >> clockFormat;
char dummy;
int h, m;
cin >> h >> dummy >> m;
if (clockFormat == 12) {
if (h >= 1 && h <= 12) {
if (h < 10) cout << 0;
cout << h;
} else if (h == 0)
cout << "01";
else if (h % 10)
cout << 0 << h % 10;
else
cout << "10";
} else {
if (h >= 1 && h <= 23) {
if (h < 10) cout << 0;
cout << h;
} else if (h == 0)
cout << "00";
else
cout << 1 << h % 10;
}
cout << ':';
if (m >= 0 && m <= 59) {
if (m < 10) cout << 0;
cout << m;
} else
cout << 1 << m % 10;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
char s[20];
while (~scanf("%d", &n)) {
scanf("%s", s);
a = s[0] - '0';
b = s[1] - '0';
c = s[3] - '0';
d = s[4] - '0';
int h = a * 10 + b, m = c * 10 + d;
if (m > 59) c = 0;
if (n == 24) {
if (h > 23) a = 0;
} else {
if (h > 12) {
if (b == 0)
a = 1;
else
a = 0;
} else if (h == 0)
b = 1;
}
printf("%d%d:%d%d\n", a, b, c, d);
}
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
char s[20];
while (~scanf("%d", &n)) {
scanf("%s", s);
a = s[0] - '0';
b = s[1] - '0';
c = s[3] - '0';
d = s[4] - '0';
int h = a * 10 + b, m = c * 10 + d;
if (m > 59) c = 0;
if (n == 24) {
if (h > 23) a = 0;
} else {
if (h > 12) {
if (b == 0)
a = 1;
else
a = 0;
} else if (h == 0)
b = 1;
}
printf("%d%d:%d%d\n", a, b, c, d);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, k;
string s;
cin >> n;
cin >> s;
if (n == 24) {
if (s[3] > '5') s[3] = '0';
if (s[0] > '2')
s[0] = '0';
else if (s[0] == '2')
if (s[1] >= '4') s[1] = '0';
} else if (n == 12) {
if (s[3] > '5') s[3] = '0';
if (s[0] > '1' && s[1] != '0')
s[0] = '0';
else if (s[0] > '1')
s[0] = '1';
else if (s[0] == '1' && s[1] > '2')
s[0] = '0';
else if (s[0] == '0' && s[1] == '0')
s[1] = '1';
}
cout << s << endl;
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, k;
string s;
cin >> n;
cin >> s;
if (n == 24) {
if (s[3] > '5') s[3] = '0';
if (s[0] > '2')
s[0] = '0';
else if (s[0] == '2')
if (s[1] >= '4') s[1] = '0';
} else if (n == 12) {
if (s[3] > '5') s[3] = '0';
if (s[0] > '1' && s[1] != '0')
s[0] = '0';
else if (s[0] > '1')
s[0] = '1';
else if (s[0] == '1' && s[1] > '2')
s[0] = '0';
else if (s[0] == '0' && s[1] == '0')
s[1] = '1';
}
cout << s << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool notinrange(string s) {
if (s[0] >= '0' && s[0] <= '5') {
return true;
}
return false;
}
bool notinrange1(string s) {
if (s[0] == '0' || s[0] == '1') {
return true;
}
if (s[0] == '2') {
if (s[1] == '0' || s[1] == '3' || s[1] == '2') {
return true;
}
}
return false;
}
bool notinrange2(string s) {
if (s[0] == '0') {
if (s[1] != '0') {
return true;
}
} else if (s[0] == '1') {
if (s[1] >= '0' && s[1] <= '2') {
return true;
}
}
return false;
}
int main() {
int l = 0, d = 0, e = 0, k = 0, n = 0, m = 0, maximum = 0,
minimum = 2147483647, p = 0, q = 0, r = 0, t = 0, end = 0, front = 0,
value = 0, first = 0, second = 0, len = 0, state = 0, size = 0;
int total = 0, temp = 0;
bool check = false;
string s, s1, s2;
cin >> s;
cin >> s1;
s2 = s1.substr(3, 2);
s1 = s1.substr(0, 2);
if (!(notinrange(s2))) {
s2 = "0" + s2.substr(1, 1);
}
if (s == "24") {
if (!(notinrange1(s1))) {
s1 = "0" + s1.substr(1, 1);
}
} else if (s == "12") {
if (!(notinrange2(s1))) {
if (s1[1] == '0') {
s1 = "10";
} else {
s1 = "0" + s1.substr(1, 1);
}
}
}
cout << s1 + ":" + s2;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool notinrange(string s) {
if (s[0] >= '0' && s[0] <= '5') {
return true;
}
return false;
}
bool notinrange1(string s) {
if (s[0] == '0' || s[0] == '1') {
return true;
}
if (s[0] == '2') {
if (s[1] == '0' || s[1] == '3' || s[1] == '2') {
return true;
}
}
return false;
}
bool notinrange2(string s) {
if (s[0] == '0') {
if (s[1] != '0') {
return true;
}
} else if (s[0] == '1') {
if (s[1] >= '0' && s[1] <= '2') {
return true;
}
}
return false;
}
int main() {
int l = 0, d = 0, e = 0, k = 0, n = 0, m = 0, maximum = 0,
minimum = 2147483647, p = 0, q = 0, r = 0, t = 0, end = 0, front = 0,
value = 0, first = 0, second = 0, len = 0, state = 0, size = 0;
int total = 0, temp = 0;
bool check = false;
string s, s1, s2;
cin >> s;
cin >> s1;
s2 = s1.substr(3, 2);
s1 = s1.substr(0, 2);
if (!(notinrange(s2))) {
s2 = "0" + s2.substr(1, 1);
}
if (s == "24") {
if (!(notinrange1(s1))) {
s1 = "0" + s1.substr(1, 1);
}
} else if (s == "12") {
if (!(notinrange2(s1))) {
if (s1[1] == '0') {
s1 = "10";
} else {
s1 = "0" + s1.substr(1, 1);
}
}
}
cout << s1 + ":" + s2;
}
```
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 2005;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
long long po(long long a, long long b, long long mod) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
} else {
return gcd(b % a, a);
}
}
int n;
int h, t;
void solve() {
scanf("%d", &(n));
scanf("%d:%d", &h, &t);
if (n == 12) {
if (h == 0) {
h++;
} else if (h >= 1 && h <= 12) {
} else {
if (h % 10 == 0) {
h = 10;
} else {
h = h % 10;
}
}
if (t >= 60) {
t = t % 10;
}
printf("%02d:%02d\n", h, t);
} else {
if (h >= 0 && h <= 23) {
} else {
h = h % 10;
}
if (t >= 60) {
t = t % 10;
}
printf("%02d:%02d\n", h, t);
}
}
int main() {
solve();
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 2005;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
long long po(long long a, long long b, long long mod) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
} else {
return gcd(b % a, a);
}
}
int n;
int h, t;
void solve() {
scanf("%d", &(n));
scanf("%d:%d", &h, &t);
if (n == 12) {
if (h == 0) {
h++;
} else if (h >= 1 && h <= 12) {
} else {
if (h % 10 == 0) {
h = 10;
} else {
h = h % 10;
}
}
if (t >= 60) {
t = t % 10;
}
printf("%02d:%02d\n", h, t);
} else {
if (h >= 0 && h <= 23) {
} else {
h = h % 10;
}
if (t >= 60) {
t = t % 10;
}
printf("%02d:%02d\n", h, t);
}
}
int main() {
solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[10];
scanf("%s", a);
int x = a[3] - '0';
if (x > 5) a[3] = '0';
x = a[0] - '0';
x = x * 10;
x = x + (a[1] - '0');
if (n == 24) {
if (x > 23) a[0] = '0';
} else {
if (x > 12) {
if (a[1] == '0') {
a[0] = '1';
} else {
a[0] = '0';
}
} else if (x == 0) {
a[1] = '1';
}
}
printf("%s", a);
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[10];
scanf("%s", a);
int x = a[3] - '0';
if (x > 5) a[3] = '0';
x = a[0] - '0';
x = x * 10;
x = x + (a[1] - '0');
if (n == 24) {
if (x > 23) a[0] = '0';
} else {
if (x > 12) {
if (a[1] == '0') {
a[0] = '1';
} else {
a[0] = '0';
}
} else if (x == 0) {
a[1] = '1';
}
}
printf("%s", a);
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int f;
scanf("%d", &f);
char s[20];
scanf("%s", s);
if (s[3] >= '6') s[3] = '0';
if (s[0] > '2') s[0] = '1';
if (f == 12) {
if (s[0] > '1') {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
if (s[0] == '1' && s[1] > '2') {
s[0] = '0';
}
if (s[0] == s[1] && s[0] == '0') {
s[0] = '1';
}
} else {
if (s[0] > '2') {
s[0] = '1';
}
if (s[0] == '2' && s[1] > '3') {
s[0] = '0';
}
}
printf("%s\n", s);
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int f;
scanf("%d", &f);
char s[20];
scanf("%s", s);
if (s[3] >= '6') s[3] = '0';
if (s[0] > '2') s[0] = '1';
if (f == 12) {
if (s[0] > '1') {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
if (s[0] == '1' && s[1] > '2') {
s[0] = '0';
}
if (s[0] == s[1] && s[0] == '0') {
s[0] = '1';
}
} else {
if (s[0] > '2') {
s[0] = '1';
}
if (s[0] == '2' && s[1] > '3') {
s[0] = '0';
}
}
printf("%s\n", s);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long mo = 1e9 + 7;
const int oo = 1 << 30;
struct edge {
int u, v;
int w;
edge() { u = v = w = 0; }
edge(int a, int b, int c) : u(a), v(b), w(c) {}
};
int main() {
int type;
cin >> type;
string s;
cin >> s;
int ans = 0;
if (s[3] >= '6') {
s[3] = '0';
}
int f = stoi(s.substr(0, 2));
if (type == 12) {
if (f == 0) {
s[0] = '1';
} else if (f > 12) {
if (f % 10 == 0) {
s[0] = '1';
} else {
s[0] = '0';
}
}
} else {
if (f >= 24) {
s[0] = '1';
}
}
cout << s;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long mo = 1e9 + 7;
const int oo = 1 << 30;
struct edge {
int u, v;
int w;
edge() { u = v = w = 0; }
edge(int a, int b, int c) : u(a), v(b), w(c) {}
};
int main() {
int type;
cin >> type;
string s;
cin >> s;
int ans = 0;
if (s[3] >= '6') {
s[3] = '0';
}
int f = stoi(s.substr(0, 2));
if (type == 12) {
if (f == 0) {
s[0] = '1';
} else if (f > 12) {
if (f % 10 == 0) {
s[0] = '1';
} else {
s[0] = '0';
}
}
} else {
if (f >= 24) {
s[0] = '1';
}
}
cout << s;
return 0;
}
```
|
#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int f, h, m;
scanf("%d", &f);
scanf("%d:%d", &h, &m);
if (m >= 60) m -= 60;
if (f == 12) {
if (h > 12) h = h % 10;
if (!h) h = 10;
} else {
if (h >= 24) h = h % 10;
}
printf("%02d:%02d\n", h, m);
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int f, h, m;
scanf("%d", &f);
scanf("%d:%d", &h, &m);
if (m >= 60) m -= 60;
if (f == 12) {
if (h > 12) h = h % 10;
if (!h) h = 10;
} else {
if (h >= 24) h = h % 10;
}
printf("%02d:%02d\n", h, m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int format;
cin >> format;
string str;
cin >> str;
int hh = (str[0] - '0') * 10 + (str[1] - '0');
int mm = (str[3] - '0') * 10 + (str[4] - '0');
if (format == 12) {
if (str[1] == '0') {
str[0] = '1';
} else if (hh > 12) {
str[0] = '0';
}
} else {
if (hh > 23) {
str[0] = '0';
}
}
if (mm > 59) {
str[3] = '0';
}
cout << str << '\n';
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int format;
cin >> format;
string str;
cin >> str;
int hh = (str[0] - '0') * 10 + (str[1] - '0');
int mm = (str[3] - '0') * 10 + (str[4] - '0');
if (format == 12) {
if (str[1] == '0') {
str[0] = '1';
} else if (hh > 12) {
str[0] = '0';
}
} else {
if (hh > 23) {
str[0] = '0';
}
}
if (mm > 59) {
str[3] = '0';
}
cout << str << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, h;
char z[10];
cin >> n >> z;
h = 0;
if (z[3] >= '6') {
z[3] = '0';
}
h += (z[0] - '0') * 10;
h += z[1] - '0';
if (n == 12) {
if (h > 12) {
if (z[0] > '1') {
z[0] = '1';
if (z[1] > '2') {
z[0] = '0';
}
} else {
if (z[0] == '0') {
if (z[1] == '0') {
z[1] = '1';
}
}
if (z[0] == '1') {
z[1] = '1';
}
}
}
if (h == 0) {
z[1] = '1';
}
} else {
if (h >= 24) {
if (z[0] > '2') {
z[0] = '1';
} else {
if (z[0] == '2') {
z[1] = '1';
}
}
}
}
for (a = 0; 5 > a; a++) {
cout << z[a];
}
cout << endl;
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, h;
char z[10];
cin >> n >> z;
h = 0;
if (z[3] >= '6') {
z[3] = '0';
}
h += (z[0] - '0') * 10;
h += z[1] - '0';
if (n == 12) {
if (h > 12) {
if (z[0] > '1') {
z[0] = '1';
if (z[1] > '2') {
z[0] = '0';
}
} else {
if (z[0] == '0') {
if (z[1] == '0') {
z[1] = '1';
}
}
if (z[0] == '1') {
z[1] = '1';
}
}
}
if (h == 0) {
z[1] = '1';
}
} else {
if (h >= 24) {
if (z[0] > '2') {
z[0] = '1';
} else {
if (z[0] == '2') {
z[1] = '1';
}
}
}
}
for (a = 0; 5 > a; a++) {
cout << z[a];
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
if (n == 24) {
if (str[0] > '2' || (str[0] == '2' && str[1] > '3')) {
char ch = '0';
str[0] = ch;
}
} else if (n == 12) {
if (str[0] > '1') {
char ch;
ch = str[1] == '0' ? '1' : '0';
str[0] = ch;
} else if (str[0] == '1' && str[1] > '2') {
char ch = '0';
str[1] = ch;
} else if (str[0] == '0' && str[1] == '0') {
char ch = '1';
str[1] = ch;
}
}
if (str[3] > '5') {
char ch = '0';
str[3] = ch;
}
cout << str << "\n";
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
if (n == 24) {
if (str[0] > '2' || (str[0] == '2' && str[1] > '3')) {
char ch = '0';
str[0] = ch;
}
} else if (n == 12) {
if (str[0] > '1') {
char ch;
ch = str[1] == '0' ? '1' : '0';
str[0] = ch;
} else if (str[0] == '1' && str[1] > '2') {
char ch = '0';
str[1] = ch;
} else if (str[0] == '0' && str[1] == '0') {
char ch = '1';
str[1] = ch;
}
}
if (str[3] > '5') {
char ch = '0';
str[3] = ch;
}
cout << str << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
char s[10];
getchar();
scanf("%s", s);
if (n == 24) {
if (s[0] > '2') s[0] = '0';
if (s[0] == '2' && s[1] >= '4') s[1] = '0';
if (s[3] > '5') s[3] = '0';
} else {
if (s[0] == '1' && s[1] > '2') s[0] = '0';
if (s[0] == '0' && s[1] == '0') s[1] = '1';
if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
if (s[3] > '5') s[3] = '0';
}
printf("%s\n", s);
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
char s[10];
getchar();
scanf("%s", s);
if (n == 24) {
if (s[0] > '2') s[0] = '0';
if (s[0] == '2' && s[1] >= '4') s[1] = '0';
if (s[3] > '5') s[3] = '0';
} else {
if (s[0] == '1' && s[1] > '2') s[0] = '0';
if (s[0] == '0' && s[1] == '0') s[1] = '1';
if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
if (s[3] > '5') s[3] = '0';
}
printf("%s\n", s);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num;
string str;
cin >> num;
cin >> str;
if (str[3] >= '6') str[3] = '0';
if (num == 12) {
if (str[0] >= '2' || (str[0] == '1' && str[1] > '2') ||
(str[0] == '0' && str[1] == '0')) {
str[0] = '0';
if (str[1] == '0') str[0] = '1';
}
} else if (num == 24) {
if (str[0] >= '3' || (str[0] == '2' && str[1] >= '4')) str[0] = '0';
}
cout << str << endl;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int num;
string str;
cin >> num;
cin >> str;
if (str[3] >= '6') str[3] = '0';
if (num == 12) {
if (str[0] >= '2' || (str[0] == '1' && str[1] > '2') ||
(str[0] == '0' && str[1] == '0')) {
str[0] = '0';
if (str[1] == '0') str[0] = '1';
}
} else if (num == 24) {
if (str[0] >= '3' || (str[0] == '2' && str[1] >= '4')) str[0] = '0';
}
cout << str << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
char ch;
long long a, b;
cin >> a >> ch >> b;
if (n == 12 && a > n && a % 10 == 0) a = 10;
if (a > n) a %= 10;
if (b > 59) b %= 10;
if (n == 12 && a == 0) a = 1;
if (n == 24 && a == n) a %= 10;
if (a < 10) cout << '0';
cout << a;
cout << ch;
if (b < 10) cout << '0';
cout << b;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
char ch;
long long a, b;
cin >> a >> ch >> b;
if (n == 12 && a > n && a % 10 == 0) a = 10;
if (a > n) a %= 10;
if (b > 59) b %= 10;
if (n == 12 && a == 0) a = 1;
if (n == 24 && a == n) a %= 10;
if (a < 10) cout << '0';
cout << a;
cout << ch;
if (b < 10) cout << '0';
cout << b;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int f, a, b;
scanf("%d", &f);
scanf("%d:%d", &a, &b);
if (b > 59) b %= 10;
if (a > f or a == 24) a %= 10;
if (a == 0 and f == 12) a = 10;
printf("%02d:%02d", a, b);
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int f, a, b;
scanf("%d", &f);
scanf("%d:%d", &a, &b);
if (b > 59) b %= 10;
if (a > f or a == 24) a %= 10;
if (a == 0 and f == 12) a = 10;
printf("%02d:%02d", a, b);
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
x += y;
if (x >= mod) x -= mod;
assert(x >= 0 && x < mod);
}
void et() {
puts("-1");
exit(0);
}
char s[10];
void fmain() {
scanf("%d", &n);
scanf("%s", s);
if (s[3] - '0' > 5) s[3] = '0';
if (n == 12) {
if (s[0] == '0') {
if (s[1] == '0') s[1] = '1';
} else if (s[0] == '1') {
if (s[1] != '0' && s[1] != '1' && s[1] != '2') s[1] = '1';
} else {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
} else {
if (s[0] == '2') {
if (s[1] - '0' > 3) s[1] = '0';
} else if (s[0] - '0' > 2)
s[0] = '0';
}
puts(s);
}
int main() {
int t = 1;
for (int(i) = 1; (i) <= (int)(t); (i)++) fmain();
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
x += y;
if (x >= mod) x -= mod;
assert(x >= 0 && x < mod);
}
void et() {
puts("-1");
exit(0);
}
char s[10];
void fmain() {
scanf("%d", &n);
scanf("%s", s);
if (s[3] - '0' > 5) s[3] = '0';
if (n == 12) {
if (s[0] == '0') {
if (s[1] == '0') s[1] = '1';
} else if (s[0] == '1') {
if (s[1] != '0' && s[1] != '1' && s[1] != '2') s[1] = '1';
} else {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
} else {
if (s[0] == '2') {
if (s[1] - '0' > 3) s[1] = '0';
} else if (s[0] - '0' > 2)
s[0] = '0';
}
puts(s);
}
int main() {
int t = 1;
for (int(i) = 1; (i) <= (int)(t); (i)++) fmain();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int a, b, clock[2], mode, min[2];
char c;
do {
cin >> mode;
} while (mode != 12 && mode != 24);
cin >> a >> c >> b;
clock[0] = a / 10;
clock[1] = a % 10;
min[0] = b / 10;
min[1] = b % 10;
if (b > 59) {
b -= 40;
min[0] = b / 10;
min[1] = b % 10;
}
if (mode == 12 && (a > 12 || a == 0)) {
if (clock[1] == 0)
clock[0] = 1;
else
clock[0] = 0;
}
if (mode == 24 && a > 23) clock[0] = 0;
cout << clock[0] << clock[1] << c << min[0] << min[1];
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int a, b, clock[2], mode, min[2];
char c;
do {
cin >> mode;
} while (mode != 12 && mode != 24);
cin >> a >> c >> b;
clock[0] = a / 10;
clock[1] = a % 10;
min[0] = b / 10;
min[1] = b % 10;
if (b > 59) {
b -= 40;
min[0] = b / 10;
min[1] = b % 10;
}
if (mode == 12 && (a > 12 || a == 0)) {
if (clock[1] == 0)
clock[0] = 1;
else
clock[0] = 0;
}
if (mode == 24 && a > 23) clock[0] = 0;
cout << clock[0] << clock[1] << c << min[0] << min[1];
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
cin >> t;
string s;
cin >> s;
int h = 10 * (s[0] - '0') + (s[1] - '0');
int m = 10 * (s[3] - '0') + (s[4] - '0');
if (t == "24" && h > 23) {
s[0] = '0';
} else if (t == "12" && h > 12 && s[1] != '0') {
s[0] = '0';
} else if (t == "12" && h > 12 && s[1] == '0') {
s[0] = '1';
} else if (t == "12" && h == 0) {
s[1] = '1';
}
if (m > 59) {
s[3] = '0';
}
std::cout << s << std::endl;
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
cin >> t;
string s;
cin >> s;
int h = 10 * (s[0] - '0') + (s[1] - '0');
int m = 10 * (s[3] - '0') + (s[4] - '0');
if (t == "24" && h > 23) {
s[0] = '0';
} else if (t == "12" && h > 12 && s[1] != '0') {
s[0] = '0';
} else if (t == "12" && h > 12 && s[1] == '0') {
s[0] = '1';
} else if (t == "12" && h == 0) {
s[1] = '1';
}
if (m > 59) {
s[3] = '0';
}
std::cout << s << std::endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int df(int a, int b) {
int ans = 0;
if (a % 10 != b % 10) ++ans;
if (a / 10 != b / 10) ++ans;
return ans;
}
int main() {
int x;
cin >> x;
int m1, m2;
int h, m;
scanf("%d:%d", &h, &m);
m2 = m % 10;
m /= 10;
if (m >= 6)
m1 = 0;
else
m1 = m;
int mn = 2;
if (x == 12) {
for (int i = 1; i <= 12; ++i) mn = min(mn, df(i, h));
} else {
for (int i = 0; i <= 23; ++i) mn = min(mn, df(i, h));
}
if (x == 12) {
for (int i = 1; i <= 12; ++i) {
if (mn == df(i, h)) {
if (i < 10) cout << 0;
cout << i << ":" << m1 << m2 << "\n";
return 0;
}
}
} else {
for (int i = 0; i <= 23; ++i) {
if (mn == df(i, h)) {
if (i < 10) cout << "0";
cout << i << ":" << m1 << m2 << "\n";
return 0;
}
}
}
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int df(int a, int b) {
int ans = 0;
if (a % 10 != b % 10) ++ans;
if (a / 10 != b / 10) ++ans;
return ans;
}
int main() {
int x;
cin >> x;
int m1, m2;
int h, m;
scanf("%d:%d", &h, &m);
m2 = m % 10;
m /= 10;
if (m >= 6)
m1 = 0;
else
m1 = m;
int mn = 2;
if (x == 12) {
for (int i = 1; i <= 12; ++i) mn = min(mn, df(i, h));
} else {
for (int i = 0; i <= 23; ++i) mn = min(mn, df(i, h));
}
if (x == 12) {
for (int i = 1; i <= 12; ++i) {
if (mn == df(i, h)) {
if (i < 10) cout << 0;
cout << i << ":" << m1 << m2 << "\n";
return 0;
}
}
} else {
for (int i = 0; i <= 23; ++i) {
if (mn == df(i, h)) {
if (i < 10) cout << "0";
cout << i << ":" << m1 << m2 << "\n";
return 0;
}
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
int main() {
int n;
scanf("%d", &n);
string S;
cin >> S;
int out[5] = {0};
if (n == 24) {
if (S[0] == '0' || S[0] == '1') {
out[0] = S[0] - '0';
out[1] = S[1] - '0';
} else if (S[0] == '2' && (int)S[1] - '0' <= 3) {
out[0] = S[0] - '0';
out[1] = S[1] - '0';
} else {
out[0] = 0;
out[1] = S[1] - '0';
}
if ((int)S[3] - '0' > 5) {
out[2] = 5;
out[3] = S[4] - '0';
} else {
out[2] = S[3] - '0';
out[3] = S[4] - '0';
}
printf("%d%d:%d%d", out[0], out[1], out[2], out[3]);
} else {
if (S[0] == '0') {
out[0] = 0;
if ((int)S[1] - '0' > 0)
out[1] = S[1] - '0';
else
out[1] = 1;
} else if (S[0] == '1' && (int)S[1] - '0' <= 2) {
out[0] = 1;
out[1] = S[1] - '0';
} else if ((int)S[0] - '0' > 1 && S[1] == '0') {
out[0] = 1;
out[1] = 0;
} else {
out[0] = 0;
out[1] = S[1] - '0';
}
if ((int)S[3] - '0' > 5) {
out[2] = 5;
out[3] = S[4] - '0';
} else {
out[2] = S[3] - '0';
out[3] = S[4] - '0';
}
printf("%d%d:%d%d", out[0], out[1], out[2], out[3]);
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
int main() {
int n;
scanf("%d", &n);
string S;
cin >> S;
int out[5] = {0};
if (n == 24) {
if (S[0] == '0' || S[0] == '1') {
out[0] = S[0] - '0';
out[1] = S[1] - '0';
} else if (S[0] == '2' && (int)S[1] - '0' <= 3) {
out[0] = S[0] - '0';
out[1] = S[1] - '0';
} else {
out[0] = 0;
out[1] = S[1] - '0';
}
if ((int)S[3] - '0' > 5) {
out[2] = 5;
out[3] = S[4] - '0';
} else {
out[2] = S[3] - '0';
out[3] = S[4] - '0';
}
printf("%d%d:%d%d", out[0], out[1], out[2], out[3]);
} else {
if (S[0] == '0') {
out[0] = 0;
if ((int)S[1] - '0' > 0)
out[1] = S[1] - '0';
else
out[1] = 1;
} else if (S[0] == '1' && (int)S[1] - '0' <= 2) {
out[0] = 1;
out[1] = S[1] - '0';
} else if ((int)S[0] - '0' > 1 && S[1] == '0') {
out[0] = 1;
out[1] = 0;
} else {
out[0] = 0;
out[1] = S[1] - '0';
}
if ((int)S[3] - '0' > 5) {
out[2] = 5;
out[3] = S[4] - '0';
} else {
out[2] = S[3] - '0';
out[3] = S[4] - '0';
}
printf("%d%d:%d%d", out[0], out[1], out[2], out[3]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
char ti[10];
int main() {
scanf("%d", &n);
scanf("%s", ti);
if (ti[3] >= '6') ti[3] = '0';
if (n == 12) {
if (ti[0] == '1' && ti[1] > '2')
ti[0] = '0';
else if (ti[0] > '1') {
if (ti[1] == '0')
ti[0] = '1';
else
ti[0] = '0';
} else if (ti[0] == '0' && ti[1] == '0')
ti[0] = '1';
} else {
if (ti[0] == '2' && ti[1] >= '4')
ti[0] = '0';
else if (ti[0] > '2')
ti[0] = '0';
}
printf("%s", ti);
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
char ti[10];
int main() {
scanf("%d", &n);
scanf("%s", ti);
if (ti[3] >= '6') ti[3] = '0';
if (n == 12) {
if (ti[0] == '1' && ti[1] > '2')
ti[0] = '0';
else if (ti[0] > '1') {
if (ti[1] == '0')
ti[0] = '1';
else
ti[0] = '0';
} else if (ti[0] == '0' && ti[1] == '0')
ti[0] = '1';
} else {
if (ti[0] == '2' && ti[1] >= '4')
ti[0] = '0';
else if (ti[0] > '2')
ti[0] = '0';
}
printf("%s", ti);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int format;
int hours;
char colon;
int minutes;
int main() {
cin >> format;
cin >> hours >> colon >> minutes;
string ans = "";
if (format == 24) {
if (hours > 23) {
hours = hours % 10;
if (hours == 0) hours = 10;
}
if (minutes > 59) {
minutes %= 10;
if (minutes == 0) minutes = 10;
}
if (hours < 10) {
if (minutes < 10)
cout << "0" << hours << ":0" << minutes << endl;
else
cout << "0" << hours << ":" << minutes << endl;
} else {
if (minutes < 10)
cout << hours << ":0" << minutes << endl;
else
cout << hours << ":" << minutes << endl;
}
} else if (format == 12) {
if (hours > 12) {
hours = hours % 10;
if (hours == 0) hours = 10;
}
if (minutes > 59) {
minutes %= 10;
if (minutes == 0) minutes = 10;
}
if (hours < 10) {
if (hours == 0) hours += 1;
if (minutes < 10)
cout << "0" << hours << ":0" << minutes << endl;
else
cout << "0" << hours << ":" << minutes << endl;
} else {
if (minutes < 10)
cout << hours << ":0" << minutes << endl;
else
cout << hours << ":" << minutes << endl;
}
}
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int format;
int hours;
char colon;
int minutes;
int main() {
cin >> format;
cin >> hours >> colon >> minutes;
string ans = "";
if (format == 24) {
if (hours > 23) {
hours = hours % 10;
if (hours == 0) hours = 10;
}
if (minutes > 59) {
minutes %= 10;
if (minutes == 0) minutes = 10;
}
if (hours < 10) {
if (minutes < 10)
cout << "0" << hours << ":0" << minutes << endl;
else
cout << "0" << hours << ":" << minutes << endl;
} else {
if (minutes < 10)
cout << hours << ":0" << minutes << endl;
else
cout << hours << ":" << minutes << endl;
}
} else if (format == 12) {
if (hours > 12) {
hours = hours % 10;
if (hours == 0) hours = 10;
}
if (minutes > 59) {
minutes %= 10;
if (minutes == 0) minutes = 10;
}
if (hours < 10) {
if (hours == 0) hours += 1;
if (minutes < 10)
cout << "0" << hours << ":0" << minutes << endl;
else
cout << "0" << hours << ":" << minutes << endl;
} else {
if (minutes < 10)
cout << hours << ":0" << minutes << endl;
else
cout << hours << ":" << minutes << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string calc(int val) {
char ss[20];
sprintf(ss, "%02d", val);
return string(ss);
}
int get(int h, int m, int hh, int mm) {
string one = calc(h) + calc(m);
string two = calc(hh) + calc(mm);
int res = 0;
for (int i = 0; i < 4; ++i) {
res += (int)(one[i] != two[i]);
}
return res;
}
int main() {
int fm;
scanf("%d", &fm);
int h, m;
scanf("%d:%d", &h, &m);
if (fm == 12) {
int cur = 10, rh = 1, rm = 0;
for (int hh = 1; hh <= 12; ++hh) {
for (int mm = 0; mm < 60; ++mm) {
if (get(h, m, hh, mm) < cur) {
cur = get(h, m, hh, mm);
rh = hh;
rm = mm;
}
}
}
printf("%02d:%02d\n", rh, rm);
} else {
int cur = 10, rh = 0, rm = 0;
for (int hh = 0; hh < 24; ++hh) {
for (int mm = 0; mm < 60; ++mm) {
if (get(h, m, hh, mm) < cur) {
cur = get(h, m, hh, mm);
rh = hh;
rm = mm;
}
}
}
printf("%02d:%02d\n", rh, rm);
}
return (0);
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string calc(int val) {
char ss[20];
sprintf(ss, "%02d", val);
return string(ss);
}
int get(int h, int m, int hh, int mm) {
string one = calc(h) + calc(m);
string two = calc(hh) + calc(mm);
int res = 0;
for (int i = 0; i < 4; ++i) {
res += (int)(one[i] != two[i]);
}
return res;
}
int main() {
int fm;
scanf("%d", &fm);
int h, m;
scanf("%d:%d", &h, &m);
if (fm == 12) {
int cur = 10, rh = 1, rm = 0;
for (int hh = 1; hh <= 12; ++hh) {
for (int mm = 0; mm < 60; ++mm) {
if (get(h, m, hh, mm) < cur) {
cur = get(h, m, hh, mm);
rh = hh;
rm = mm;
}
}
}
printf("%02d:%02d\n", rh, rm);
} else {
int cur = 10, rh = 0, rm = 0;
for (int hh = 0; hh < 24; ++hh) {
for (int mm = 0; mm < 60; ++mm) {
if (get(h, m, hh, mm) < cur) {
cur = get(h, m, hh, mm);
rh = hh;
rm = mm;
}
}
}
printf("%02d:%02d\n", rh, rm);
}
return (0);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int format;
cin >> format;
string t;
cin >> t;
vector<int> time{t[0] - '0', t[1] - '0', t[3] - '0', t[4] - '0'};
if (format == 12) {
if (time[0] > 1) {
t[0] = '0';
time[0] = 0;
if (time[1] == 0) {
t[0] = '1';
time[0] = 1;
}
}
if (time[0] == 1) {
if (time[1] > 2) {
t[1] = '2';
}
}
if (time[0] == 0 && time[1] == 0) {
t[1] = '1';
}
} else {
if (time[0] > 2) {
t[0] = '0';
time[0] = 0;
}
if (time[0] == 2) {
if (time[1] > 3) {
t[1] = '3';
}
}
}
if (time[2] > 5) {
t[3] = '0';
}
cout << t << endl;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int format;
cin >> format;
string t;
cin >> t;
vector<int> time{t[0] - '0', t[1] - '0', t[3] - '0', t[4] - '0'};
if (format == 12) {
if (time[0] > 1) {
t[0] = '0';
time[0] = 0;
if (time[1] == 0) {
t[0] = '1';
time[0] = 1;
}
}
if (time[0] == 1) {
if (time[1] > 2) {
t[1] = '2';
}
}
if (time[0] == 0 && time[1] == 0) {
t[1] = '1';
}
} else {
if (time[0] > 2) {
t[0] = '0';
time[0] = 0;
}
if (time[0] == 2) {
if (time[1] > 3) {
t[1] = '3';
}
}
}
if (time[2] > 5) {
t[3] = '0';
}
cout << t << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
uint16_t format;
cin >> format;
string time;
cin >> time;
time[3] >= '6' ? time[3] = '0' : time[3];
if (format == 12) {
if (time[0] >= '1' && time[1] >= '3')
time[0] = '0';
else if (time[0] >= '2' && time[1] != '0')
time[0] = '0';
else if (time[0] >= '2' && time[1] == '0')
time[0] = '1';
else if (time[0] == '0' && time[1] == '0')
time[1] = '1';
} else {
if (time[0] >= '2' && time[1] >= '4')
time[0] = '0';
else if (time[0] >= '3')
time[0] = '0';
}
cout << time << endl;
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
uint16_t format;
cin >> format;
string time;
cin >> time;
time[3] >= '6' ? time[3] = '0' : time[3];
if (format == 12) {
if (time[0] >= '1' && time[1] >= '3')
time[0] = '0';
else if (time[0] >= '2' && time[1] != '0')
time[0] = '0';
else if (time[0] >= '2' && time[1] == '0')
time[0] = '1';
else if (time[0] == '0' && time[1] == '0')
time[1] = '1';
} else {
if (time[0] >= '2' && time[1] >= '4')
time[0] = '0';
else if (time[0] >= '3')
time[0] = '0';
}
cout << time << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
int cal(int x, int y) {
int res = 0;
res += (x % 10) != (y % 10);
res += (x / 10) != (y / 10);
return res;
}
string ti(int x, int y) {
string res = "";
res.push_back(char((x / 10) + '0'));
res.push_back(char((x % 10) + '0'));
res.push_back(':');
res.push_back(char((y / 10) + '0'));
res.push_back(char((y % 10) + '0'));
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string line;
getline(cin, line);
stringstream ss(line);
ss >> n;
string t;
int res = 200;
string opt = "";
getline(cin, t);
int h = (t[0] - '0') * 10 + (t[1] - '0');
int m = (t[3] - '0') * 10 + (t[4] - '0');
for (int i = ((n == 12) ? 1 : 0); i <= ((n == 12) ? 12 : 23); ++i) {
for (int j = 0; j < 60; ++j) {
int tmp = cal(h, i) + cal(m, j);
res = min(res, tmp);
if (res == tmp) {
opt = ti(i, j);
}
}
}
cout << opt << endl;
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int cal(int x, int y) {
int res = 0;
res += (x % 10) != (y % 10);
res += (x / 10) != (y / 10);
return res;
}
string ti(int x, int y) {
string res = "";
res.push_back(char((x / 10) + '0'));
res.push_back(char((x % 10) + '0'));
res.push_back(':');
res.push_back(char((y / 10) + '0'));
res.push_back(char((y % 10) + '0'));
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string line;
getline(cin, line);
stringstream ss(line);
ss >> n;
string t;
int res = 200;
string opt = "";
getline(cin, t);
int h = (t[0] - '0') * 10 + (t[1] - '0');
int m = (t[3] - '0') * 10 + (t[4] - '0');
for (int i = ((n == 12) ? 1 : 0); i <= ((n == 12) ? 12 : 23); ++i) {
for (int j = 0; j < 60; ++j) {
int tmp = cal(h, i) + cal(m, j);
res = min(res, tmp);
if (res == tmp) {
opt = ti(i, j);
}
}
}
cout << opt << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int f;
string x;
int H, M;
bool hd, md;
void print(int x) {
if (x >= 10)
cout << x;
else
cout << '0' << x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> f;
cin >> x;
H = (x[0] - '0') * 10 + x[1] - '0';
M = x[3] * 10 + x[4] - 11 * '0';
if (f == 12) {
if (0 < H && H < 13) {
} else {
if (H == 0) {
H = 1;
} else {
H = H % 10;
if (H == 0) {
H = 10;
}
}
}
}
if (f == 24) {
if (H < 24) {
} else {
H = H % 10 + 10;
}
}
if (M > 59) {
M = M % 10;
}
print(H);
cout << ":";
print(M);
cout << endl;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int f;
string x;
int H, M;
bool hd, md;
void print(int x) {
if (x >= 10)
cout << x;
else
cout << '0' << x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> f;
cin >> x;
H = (x[0] - '0') * 10 + x[1] - '0';
M = x[3] * 10 + x[4] - 11 * '0';
if (f == 12) {
if (0 < H && H < 13) {
} else {
if (H == 0) {
H = 1;
} else {
H = H % 10;
if (H == 0) {
H = 10;
}
}
}
}
if (f == 24) {
if (H < 24) {
} else {
H = H % 10 + 10;
}
}
if (M > 59) {
M = M % 10;
}
print(H);
cout << ":";
print(M);
cout << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int v[104];
int c[103];
int v1[104];
long long gcd(long long i, long long j) {
if (i % j == 0) return j;
return gcd(j, i % j);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long n;
string s;
cin >> n >> s;
if (n == 24) {
int d = (s[0] - '0') * 10 + s[1] - '0';
int f = (s[3] - '0') * 10 + s[4] - '0';
if (f > 59) {
s[3] = '0';
}
if (d > 23) s[0] = '0';
cout << s << endl;
return 0;
}
int d = (s[0] - '0') * 10 + s[1] - '0';
int f = (s[3] - '0') * 10 + s[4] - '0';
if (d > 12) {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
if (d == 0) {
s[1] = '1';
}
if (f > 59) {
s[3] = '0';
}
cout << s << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int v[104];
int c[103];
int v1[104];
long long gcd(long long i, long long j) {
if (i % j == 0) return j;
return gcd(j, i % j);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long n;
string s;
cin >> n >> s;
if (n == 24) {
int d = (s[0] - '0') * 10 + s[1] - '0';
int f = (s[3] - '0') * 10 + s[4] - '0';
if (f > 59) {
s[3] = '0';
}
if (d > 23) s[0] = '0';
cout << s << endl;
return 0;
}
int d = (s[0] - '0') * 10 + s[1] - '0';
int f = (s[3] - '0') * 10 + s[4] - '0';
if (d > 12) {
if (s[1] != '0')
s[0] = '0';
else
s[0] = '1';
}
if (d == 0) {
s[1] = '1';
}
if (f > 59) {
s[3] = '0';
}
cout << s << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long int, long long int>;
class prioritize {
public:
bool operator()(ii &p1, ii &p2) { return p1.first < p2.first; }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n;
cin >> n;
string s;
cin >> s;
long long int l1 = s[0] - '0';
long long int l2 = s[1] - '0';
long long int r2 = s[3] - '0';
long long int r1 = s[4] - '0';
long long int cc = 0;
if (n == 12) {
if (r2 >= 6) {
r2 = 1;
cc++;
}
if (l2 > 2 || l1 > 1) {
if (l2 > 0)
l1 = 0;
else
l1 = 1;
cc++;
}
if (l1 == 0 && l2 == 0) {
cc++;
l2 = 1;
}
cout << l1 << l2 << ":" << r2 << r1 << "\n";
} else {
if (r2 >= 6) {
r2 = 1;
cc++;
}
if (l1 == 2 && (l2 >= 4)) {
l1 = 0;
cc++;
}
if (l1 > 2) {
l1 = 0;
cc++;
}
cout << l1 << l2 << ":" << r2 << r1 << "\n";
}
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long int, long long int>;
class prioritize {
public:
bool operator()(ii &p1, ii &p2) { return p1.first < p2.first; }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n;
cin >> n;
string s;
cin >> s;
long long int l1 = s[0] - '0';
long long int l2 = s[1] - '0';
long long int r2 = s[3] - '0';
long long int r1 = s[4] - '0';
long long int cc = 0;
if (n == 12) {
if (r2 >= 6) {
r2 = 1;
cc++;
}
if (l2 > 2 || l1 > 1) {
if (l2 > 0)
l1 = 0;
else
l1 = 1;
cc++;
}
if (l1 == 0 && l2 == 0) {
cc++;
l2 = 1;
}
cout << l1 << l2 << ":" << r2 << r1 << "\n";
} else {
if (r2 >= 6) {
r2 = 1;
cc++;
}
if (l1 == 2 && (l2 >= 4)) {
l1 = 0;
cc++;
}
if (l1 > 2) {
l1 = 0;
cc++;
}
cout << l1 << l2 << ":" << r2 << r1 << "\n";
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
string s;
cin >> s;
int h = 10 * (s[0] - '0') + (s[1] - '0');
int m = 10 * (s[3] - '0') + (s[4] - '0');
if (n == 24) {
if (h < 0 || h >= 24) h = h % 10 + 10;
} else {
if (h < 1 || h > 12) {
if (h % 10 == 0) {
h = 10;
} else {
h = h % 10;
}
}
}
if (m < 0 || m > 59) {
m = m % 10;
}
if (h < 10) cout << "0";
cout << h << ":";
if (m < 10) cout << "0";
cout << m;
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
string s;
cin >> s;
int h = 10 * (s[0] - '0') + (s[1] - '0');
int m = 10 * (s[3] - '0') + (s[4] - '0');
if (n == 24) {
if (h < 0 || h >= 24) h = h % 10 + 10;
} else {
if (h < 1 || h > 12) {
if (h % 10 == 0) {
h = 10;
} else {
h = h % 10;
}
}
}
if (m < 0 || m > 59) {
m = m % 10;
}
if (h < 10) cout << "0";
cout << h << ":";
if (m < 10) cout << "0";
cout << m;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[10];
int n, ans = 0;
scanf("%d", &n);
scanf("%s", str);
int hr = (str[0] - 48) * 10 + str[1] - 48;
int mn = (str[3] - 48) * 10 + str[4] - 48;
if (n == 12 and (hr == 0 or hr > 12)) {
if (str[1] == 48)
str[0] = 49;
else
str[0] = 48;
}
if (n == 24 and (hr > 23)) {
str[0] = 48;
}
if (mn > 59) str[3] = 48;
printf("%s\n", str);
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[10];
int n, ans = 0;
scanf("%d", &n);
scanf("%s", str);
int hr = (str[0] - 48) * 10 + str[1] - 48;
int mn = (str[3] - 48) * 10 + str[4] - 48;
if (n == 12 and (hr == 0 or hr > 12)) {
if (str[1] == 48)
str[0] = 49;
else
str[0] = 48;
}
if (n == 24 and (hr > 23)) {
str[0] = 48;
}
if (mn > 59) str[3] = 48;
printf("%s\n", str);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > getStep(int nh, int nm, int h, int m) {
pair<int, pair<int, int> > ret;
ret.second = make_pair(nh, nm);
ret.first += nh / 10 != h / 10;
ret.first += nh % 10 != h % 10;
ret.first += nm % 10 != m % 10;
ret.first += nm / 10 != m / 10;
return ret;
}
int main() {
int T, h, m;
scanf("%d%d:%d", &T, &h, &m);
pair<int, pair<int, int> > ans(1000, make_pair(0, 0));
if (T == 12) {
for (int nh = 1, ed_nh = 12; nh <= ed_nh; nh++) {
for (int nm = 0, ed_nm = 60; nm < ed_nm; nm++) {
ans = min(ans, getStep(nh, nm, h, m));
}
}
} else {
for (int nh = 0, ed_nh = 24; nh < ed_nh; nh++) {
for (int nm = 0, ed_nm = 60; nm < ed_nm; nm++) {
ans = min(ans, getStep(nh, nm, h, m));
}
}
}
printf("%02d:%02d\n", ans.second.first, ans.second.second);
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > getStep(int nh, int nm, int h, int m) {
pair<int, pair<int, int> > ret;
ret.second = make_pair(nh, nm);
ret.first += nh / 10 != h / 10;
ret.first += nh % 10 != h % 10;
ret.first += nm % 10 != m % 10;
ret.first += nm / 10 != m / 10;
return ret;
}
int main() {
int T, h, m;
scanf("%d%d:%d", &T, &h, &m);
pair<int, pair<int, int> > ans(1000, make_pair(0, 0));
if (T == 12) {
for (int nh = 1, ed_nh = 12; nh <= ed_nh; nh++) {
for (int nm = 0, ed_nm = 60; nm < ed_nm; nm++) {
ans = min(ans, getStep(nh, nm, h, m));
}
}
} else {
for (int nh = 0, ed_nh = 24; nh < ed_nh; nh++) {
for (int nm = 0, ed_nm = 60; nm < ed_nm; nm++) {
ans = min(ans, getStep(nh, nm, h, m));
}
}
}
printf("%02d:%02d\n", ans.second.first, ans.second.second);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, m;
scanf("%d", &n);
scanf("%d:%d", &h, &m);
if (n == 12) {
if (h == 0) h = 1;
if (h > 12) {
if (h % 10)
h = h % 10;
else
h = 10;
}
} else {
if (h > 23) {
h = h % 10;
}
}
if (m > 59) {
m = m % 10;
}
printf("%02d:%02d", h, m);
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, h, m;
scanf("%d", &n);
scanf("%d:%d", &h, &m);
if (n == 12) {
if (h == 0) h = 1;
if (h > 12) {
if (h % 10)
h = h % 10;
else
h = 10;
}
} else {
if (h > 23) {
h = h % 10;
}
}
if (m > 59) {
m = m % 10;
}
printf("%02d:%02d", h, m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
int HH, MM;
char ch;
cin >> a;
cin >> HH >> ch >> MM;
if (a == 24) {
if (HH > 23) {
HH = HH % 10;
}
if (MM > 59) MM = MM % 10;
} else {
if (HH > 12) {
HH = HH % 10;
if (HH == 0) HH = 10;
} else {
if (HH == 0) HH = 1;
}
if (MM > 59) {
MM = MM % 10;
}
}
cout << setw(2) << setfill('0') << HH << ":";
cout << setw(2) << setfill('0') << MM << endl;
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
int HH, MM;
char ch;
cin >> a;
cin >> HH >> ch >> MM;
if (a == 24) {
if (HH > 23) {
HH = HH % 10;
}
if (MM > 59) MM = MM % 10;
} else {
if (HH > 12) {
HH = HH % 10;
if (HH == 0) HH = 10;
} else {
if (HH == 0) HH = 1;
}
if (MM > 59) {
MM = MM % 10;
}
}
cout << setw(2) << setfill('0') << HH << ":";
cout << setw(2) << setfill('0') << MM << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int mod, h, m;
char c;
cin >> mod >> h >> c >> m;
if (mod == 12) {
if (h == 0) {
cout << "01";
} else if (h <= 12) {
if (h < 10) cout << 0;
cout << h;
} else if (h > 12) {
if (h % 10 == 0)
cout << 10;
else
cout << 0 << h % 10;
}
cout << ':';
}
if (mod == 24) {
if (h <= 23) {
if (h < 10) cout << 0;
cout << h;
} else if (h > 23) {
cout << 0 << h % 10;
}
cout << ':';
}
if (m >= 60)
cout << 0 << m % 10;
else {
if (m < 10) cout << 0;
cout << m;
}
}
|
### Prompt
Create a solution in CPP for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int mod, h, m;
char c;
cin >> mod >> h >> c >> m;
if (mod == 12) {
if (h == 0) {
cout << "01";
} else if (h <= 12) {
if (h < 10) cout << 0;
cout << h;
} else if (h > 12) {
if (h % 10 == 0)
cout << 10;
else
cout << 0 << h % 10;
}
cout << ':';
}
if (mod == 24) {
if (h <= 23) {
if (h < 10) cout << 0;
cout << h;
} else if (h > 23) {
cout << 0 << h % 10;
}
cout << ':';
}
if (m >= 60)
cout << 0 << m % 10;
else {
if (m < 10) cout << 0;
cout << m;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int cmd, h, m;
scanf("%d", &cmd);
scanf("%d:%d", &h, &m);
m = m % 60;
if (cmd == 12) {
if (h == 0) h = 10;
if (h > 12) {
if (h % 10 == 0)
h = 10;
else
h = h % 10;
}
} else {
if (h >= 24) {
h %= 10;
}
}
if (h < 10)
printf("0%d:", h);
else
printf("%d:", h);
if (m < 10)
printf("0%d\n", m);
else
printf("%d\n", m);
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int cmd, h, m;
scanf("%d", &cmd);
scanf("%d:%d", &h, &m);
m = m % 60;
if (cmd == 12) {
if (h == 0) h = 10;
if (h > 12) {
if (h % 10 == 0)
h = 10;
else
h = h % 10;
}
} else {
if (h >= 24) {
h %= 10;
}
}
if (h < 10)
printf("0%d:", h);
else
printf("%d:", h);
if (m < 10)
printf("0%d\n", m);
else
printf("%d\n", m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b1 >> b2;
if (n == 24) {
if ((a1 - '0') * 10 + a2 - '0' > 23) {
a1 = '0';
}
} else {
if (a1 - '0' == 1 && (a1 - '0') * 10 + a2 - '0' > 12) a2 = '0';
if ((a1 - '0') * 10 + a2 - '0' > 12) {
if (a2 - '0' <= 2)
a1 = '1';
else
a1 = '0';
}
if (a1 == '0' && a2 == '0') {
a2 = '1';
}
}
if ((b1 - '0') * 10 + b2 - '0' > 59) {
b1 = '0';
}
cout << a1 << a2 << ':' << b1 << b2;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b1 >> b2;
if (n == 24) {
if ((a1 - '0') * 10 + a2 - '0' > 23) {
a1 = '0';
}
} else {
if (a1 - '0' == 1 && (a1 - '0') * 10 + a2 - '0' > 12) a2 = '0';
if ((a1 - '0') * 10 + a2 - '0' > 12) {
if (a2 - '0' <= 2)
a1 = '1';
else
a1 = '0';
}
if (a1 == '0' && a2 == '0') {
a2 = '1';
}
}
if ((b1 - '0') * 10 + b2 - '0' > 59) {
b1 = '0';
}
cout << a1 << a2 << ':' << b1 << b2;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int n;
while (cin >> n >> s) {
if (n == 12) {
if (s[0] == '0') {
if (s[1] == '0') s[0] = '1';
}
if (s[0] == '1') {
if (s[1] > '2') s[0] = '0';
}
if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
if (s[3] > '5') {
s[3] = '0';
}
} else if (n == 24) {
if (s[0] == '2') {
if (s[1] > '3') s[0] = '0';
}
if (s[0] > '2') {
s[0] = '0';
}
if (s[3] > '5') {
s[3] = '0';
}
}
cout << s << endl;
}
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int n;
while (cin >> n >> s) {
if (n == 12) {
if (s[0] == '0') {
if (s[1] == '0') s[0] = '1';
}
if (s[0] == '1') {
if (s[1] > '2') s[0] = '0';
}
if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
if (s[3] > '5') {
s[3] = '0';
}
} else if (n == 24) {
if (s[0] == '2') {
if (s[1] > '3') s[0] = '0';
}
if (s[0] > '2') {
s[0] = '0';
}
if (s[3] > '5') {
s[3] = '0';
}
}
cout << s << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int hour;
cin >> hour;
string s;
cin >> s;
if (hour == 12) {
if (s[0] == '0') {
if (s[1] == '0') {
s[1] = '1';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else if (s[0] == '1') {
if (s[1] >= '3') {
s[0] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else {
if (s[1] <= '2') {
s[0] = '1';
} else {
s[0] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
}
} else {
if (s[0] == '0') {
if (s[3] >= '6') {
s[3] = '0';
}
} else if (s[0] == '1') {
if (s[3] >= '6') {
s[3] = '0';
}
} else if (s[0] == '2') {
if (s[1] >= '4') {
s[1] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else {
s[0] = '0';
if (s[3] >= '6') {
s[3] = '0';
}
}
}
cout << s;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int hour;
cin >> hour;
string s;
cin >> s;
if (hour == 12) {
if (s[0] == '0') {
if (s[1] == '0') {
s[1] = '1';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else if (s[0] == '1') {
if (s[1] >= '3') {
s[0] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else {
if (s[1] <= '2') {
s[0] = '1';
} else {
s[0] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
}
} else {
if (s[0] == '0') {
if (s[3] >= '6') {
s[3] = '0';
}
} else if (s[0] == '1') {
if (s[3] >= '6') {
s[3] = '0';
}
} else if (s[0] == '2') {
if (s[1] >= '4') {
s[1] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else {
s[0] = '0';
if (s[3] >= '6') {
s[3] = '0';
}
}
}
cout << s;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void solve(int tp) {
assert(tp == 12 || tp == 24);
string tm;
cin >> tm;
assert((int)(tm).size() == 5 && tm[2] == ':');
int bst = 10;
string ans = "";
for (int rm = 0; rm < 60; rm++) {
int l = (tp == 12 ? 1 : 0);
int r = (tp == 12 ? 13 : 24);
for (int rh = l; rh < r; rh++) {
string cur;
cur += (rh / 10) + '0';
cur += (rh % 10) + '0';
cur += ':';
cur += (rm / 10) + '0';
cur += (rm % 10) + '0';
int cnt = 0;
for (int i = 0; i < 5; i++) cnt += (cur[i] != tm[i]);
if (cnt < bst) bst = cnt, ans = cur;
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
while (cin >> n) solve(n);
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve(int tp) {
assert(tp == 12 || tp == 24);
string tm;
cin >> tm;
assert((int)(tm).size() == 5 && tm[2] == ':');
int bst = 10;
string ans = "";
for (int rm = 0; rm < 60; rm++) {
int l = (tp == 12 ? 1 : 0);
int r = (tp == 12 ? 13 : 24);
for (int rh = l; rh < r; rh++) {
string cur;
cur += (rh / 10) + '0';
cur += (rh % 10) + '0';
cur += ':';
cur += (rm / 10) + '0';
cur += (rm % 10) + '0';
int cnt = 0;
for (int i = 0; i < 5; i++) cnt += (cur[i] != tm[i]);
if (cnt < bst) bst = cnt, ans = cur;
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
while (cin >> n) solve(n);
}
```
|
#include <bits/stdc++.h>
int main() {
int t, m, n, a, b, c, d;
do scanf("%d", &n);
while ((n != 12) && (n != 24));
scanf("%d:%d", &t, &m);
a = t % 10;
b = m % 10;
c = m / 10;
d = t / 10;
if (n == 24) {
if ((d > 2) || ((d == 2) && (a > 3))) d = 0;
if (c > 5) c = 0;
} else {
if (c > 5) c = 0;
if (((d > 1) || ((d == 1) && (a > 2))) && (a != 0))
d = 0;
else if ((d == 0) && (a == 0))
a = 1;
else if (((d > 1) || ((d == 1) && (a > 2))) && (a == 0))
d = 1;
}
printf("%d%d:%d%d", d, a, c, b);
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int t, m, n, a, b, c, d;
do scanf("%d", &n);
while ((n != 12) && (n != 24));
scanf("%d:%d", &t, &m);
a = t % 10;
b = m % 10;
c = m / 10;
d = t / 10;
if (n == 24) {
if ((d > 2) || ((d == 2) && (a > 3))) d = 0;
if (c > 5) c = 0;
} else {
if (c > 5) c = 0;
if (((d > 1) || ((d == 1) && (a > 2))) && (a != 0))
d = 0;
else if ((d == 0) && (a == 0))
a = 1;
else if (((d > 1) || ((d == 1) && (a > 2))) && (a == 0))
d = 1;
}
printf("%d%d:%d%d", d, a, c, b);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, count = 0;
char a[10001], a1 = '6';
cin >> n;
for (i = 0; i < 5; i++) cin >> a[i];
if (n == 12) {
if (a[1] == '0' && a[0] == '0') a[1] = '1';
if ((int)a[3] >= 54) a[3] = '0';
if ((int)a[0] >= 49 && (int)a[1] > 50) a[0] = '0';
if ((int)a[0] > 49) a[0] = '1';
} else {
if ((int)a[3] >= 54) a[3] = '0';
if ((int)a[0] >= 50 && (int)a[1] > 51) a[0] = '0';
if ((int)a[0] > 50) a[0] = '0';
}
for (i = 0; i < 5; i++) {
cout << a[i];
}
}
|
### Prompt
Please formulate a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, count = 0;
char a[10001], a1 = '6';
cin >> n;
for (i = 0; i < 5; i++) cin >> a[i];
if (n == 12) {
if (a[1] == '0' && a[0] == '0') a[1] = '1';
if ((int)a[3] >= 54) a[3] = '0';
if ((int)a[0] >= 49 && (int)a[1] > 50) a[0] = '0';
if ((int)a[0] > 49) a[0] = '1';
} else {
if ((int)a[3] >= 54) a[3] = '0';
if ((int)a[0] >= 50 && (int)a[1] > 51) a[0] = '0';
if ((int)a[0] > 50) a[0] = '0';
}
for (i = 0; i < 5; i++) {
cout << a[i];
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int ar[101];
int main() {
int n, ans;
string t;
while (cin >> n >> t) {
int h, m;
if (n == 12) {
h = (t[0] - '0') * 10 + (t[1] - '0');
m = (t[3] - '0') * 10 + (t[4] - '0');
if (t[0] == '0' && t[1] == '0')
t[1] = '1';
else if (t[0] == '1' && t[1] > '2')
t[1] = '1';
else if (t[0] > '1' && t[1] != '0')
t[0] = '0';
else if (t[0] > '1' && t[1] == '0')
t[0] = '1';
if (t[3] > '5') t[3] = '0';
} else {
h = (t[0] - '0') * 10 + (t[1] - '0');
m = (t[3] - '0') * 10 + (t[4] - '0');
if (t[0] > '2')
t[0] = '0';
else if (t[0] == '2' && t[1] > '3')
t[1] = '1';
else if (t[0] > '3')
t[0] = '0';
if (t[3] > '5') t[3] = '0';
}
cout << t << "\n";
}
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int ar[101];
int main() {
int n, ans;
string t;
while (cin >> n >> t) {
int h, m;
if (n == 12) {
h = (t[0] - '0') * 10 + (t[1] - '0');
m = (t[3] - '0') * 10 + (t[4] - '0');
if (t[0] == '0' && t[1] == '0')
t[1] = '1';
else if (t[0] == '1' && t[1] > '2')
t[1] = '1';
else if (t[0] > '1' && t[1] != '0')
t[0] = '0';
else if (t[0] > '1' && t[1] == '0')
t[0] = '1';
if (t[3] > '5') t[3] = '0';
} else {
h = (t[0] - '0') * 10 + (t[1] - '0');
m = (t[3] - '0') * 10 + (t[4] - '0');
if (t[0] > '2')
t[0] = '0';
else if (t[0] == '2' && t[1] > '3')
t[1] = '1';
else if (t[0] > '3')
t[0] = '0';
if (t[3] > '5') t[3] = '0';
}
cout << t << "\n";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
string s;
cin >> s;
if (n == 24) {
if (s[0] == '2' && s[1] > '3') {
s[0] = '1';
} else if (s[0] > '2') {
s[0] = '1';
}
} else {
if (s[0] == '1' && s[1] > '2') {
s[0] = '0';
} else if (s[0] == '0' && s[1] == '0') {
s[1] = '1';
} else if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
}
if (s[3] > '5') {
s[3] = '1';
}
cout << s;
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
string s;
cin >> s;
if (n == 24) {
if (s[0] == '2' && s[1] > '3') {
s[0] = '1';
} else if (s[0] > '2') {
s[0] = '1';
}
} else {
if (s[0] == '1' && s[1] > '2') {
s[0] = '0';
} else if (s[0] == '0' && s[1] == '0') {
s[1] = '1';
} else if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else
s[0] = '0';
}
}
if (s[3] > '5') {
s[3] = '1';
}
cout << s;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 5;
int n, m, h, hh, mm;
int main() {
scanf("%d", &n);
scanf("%d:%d", &h, &m);
hh = h / 10;
h = h % 10;
mm = m / 10;
m = m % 10;
switch (n) {
case 12:
if (hh > 1) {
if (h == 0)
hh = 1;
else
hh = 0;
} else {
if (hh == 1) {
if (h > 2) h = 0;
} else if (h == 0)
h = 1;
}
case 24:
if (hh * 10 + h > 23) hh = 0;
break;
}
if (mm > 5) mm = 0;
printf("%d%d:%d%d\n", hh, h, mm, m);
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 5;
int n, m, h, hh, mm;
int main() {
scanf("%d", &n);
scanf("%d:%d", &h, &m);
hh = h / 10;
h = h % 10;
mm = m / 10;
m = m % 10;
switch (n) {
case 12:
if (hh > 1) {
if (h == 0)
hh = 1;
else
hh = 0;
} else {
if (hh == 1) {
if (h > 2) h = 0;
} else if (h == 0)
h = 1;
}
case 24:
if (hh * 10 + h > 23) hh = 0;
break;
}
if (mm > 5) mm = 0;
printf("%d%d:%d%d\n", hh, h, mm, m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, h, m;
scanf("%d%d:%d", &t, &h, &m);
if (t == 12) {
if (h / 10 >= 2) {
if (h % 10 == 0)
h = 10;
else
h = h % 10;
}
if (h / 10 == 1 && h % 10 >= 3) h = 10;
if (h == 0) h = 1;
} else {
if (h / 10 >= 3)
h = h % 10;
else if (h > 23)
h = 20;
}
if (m > 59) m = m % 10;
printf("%02d:%02d\n", h, m);
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, h, m;
scanf("%d%d:%d", &t, &h, &m);
if (t == 12) {
if (h / 10 >= 2) {
if (h % 10 == 0)
h = 10;
else
h = h % 10;
}
if (h / 10 == 1 && h % 10 >= 3) h = 10;
if (h == 0) h = 1;
} else {
if (h / 10 >= 3)
h = h % 10;
else if (h > 23)
h = 20;
}
if (m > 59) m = m % 10;
printf("%02d:%02d\n", h, m);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
char s[10];
scanf("%d %s", &t, s);
if (t == 12) {
if (s[0] > '1' || (s[0] == '1' && s[1] >= '3')) s[0] = '0';
if ((s[0] == '0') && (s[1] == '0')) s[0] = '1';
if (s[3] > '5') s[3] = '0';
} else {
if (s[0] > '2' || (s[0] == '2' && s[1] >= '4')) s[0] = '0';
if (s[3] > '5') s[3] = '0';
}
printf("%s\n", s);
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
char s[10];
scanf("%d %s", &t, s);
if (t == 12) {
if (s[0] > '1' || (s[0] == '1' && s[1] >= '3')) s[0] = '0';
if ((s[0] == '0') && (s[1] == '0')) s[0] = '1';
if (s[3] > '5') s[3] = '0';
} else {
if (s[0] > '2' || (s[0] == '2' && s[1] >= '4')) s[0] = '0';
if (s[3] > '5') s[3] = '0';
}
printf("%s\n", s);
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int h1, m1, h2, m2, n, H, M;
scanf("%d", &n);
scanf("%d:%d", &H, &M);
h1 = H / 10;
h2 = H % 10;
m1 = M / 10;
m2 = M % 10;
if (m1 > 5) m1 = 0;
if (n == 24) {
if ((h1 * 10 + h2) >= 24) h1 = 1;
}
if (n == 12) {
if ((h1 * 10 + h2) > 12) {
if (h2 == 0) {
h1 = 1;
} else {
h1 = 0;
}
} else if (h1 == 0 && h2 == 0) {
h2 = 1;
}
}
printf("%d%d:%d%d", h1, h2, m1, m2);
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int h1, m1, h2, m2, n, H, M;
scanf("%d", &n);
scanf("%d:%d", &H, &M);
h1 = H / 10;
h2 = H % 10;
m1 = M / 10;
m2 = M % 10;
if (m1 > 5) m1 = 0;
if (n == 24) {
if ((h1 * 10 + h2) >= 24) h1 = 1;
}
if (n == 12) {
if ((h1 * 10 + h2) > 12) {
if (h2 == 0) {
h1 = 1;
} else {
h1 = 0;
}
} else if (h1 == 0 && h2 == 0) {
h2 = 1;
}
}
printf("%d%d:%d%d", h1, h2, m1, m2);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
char op[4];
char s[16];
int hh, mm;
int ans = 0;
cin >> op >> s;
hh = (s[0] - '0') * 10 + (s[1] - '0');
mm = (s[3] - '0') * 10 + (s[4] - '0');
if (mm > 59) {
s[3] = '0';
}
if (op[0] == '1') {
if (hh == 0) {
s[1] = '1';
} else if (hh > 12) {
if (hh % 10 == 0)
s[0] = '1';
else
s[0] = '0';
}
} else {
if (hh > 23) {
s[0] = '0';
}
}
puts(s);
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
char op[4];
char s[16];
int hh, mm;
int ans = 0;
cin >> op >> s;
hh = (s[0] - '0') * 10 + (s[1] - '0');
mm = (s[3] - '0') * 10 + (s[4] - '0');
if (mm > 59) {
s[3] = '0';
}
if (op[0] == '1') {
if (hh == 0) {
s[1] = '1';
} else if (hh > 12) {
if (hh % 10 == 0)
s[0] = '1';
else
s[0] = '0';
}
} else {
if (hh > 23) {
s[0] = '0';
}
}
puts(s);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int type;
cin >> type;
string t;
cin >> t;
if (type == 12) {
if (t[0] > '1' && t[1] <= '2') t[0] = '1';
if (t[0] > '1' || t[0] == '1' && t[1] > '2') t[0] = '0';
if (t[0] == t[1] && t[0] == '0') t[1] = '2';
} else {
if (t[0] > '2' || t[0] == '2' && t[1] >= '4') t[0] = '0';
}
if (t[3] > '5') t[3] = '5';
cout << t << endl;
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int type;
cin >> type;
string t;
cin >> t;
if (type == 12) {
if (t[0] > '1' && t[1] <= '2') t[0] = '1';
if (t[0] > '1' || t[0] == '1' && t[1] > '2') t[0] = '0';
if (t[0] == t[1] && t[0] == '0') t[1] = '2';
} else {
if (t[0] > '2' || t[0] == '2' && t[1] >= '4') t[0] = '0';
}
if (t[3] > '5') t[3] = '5';
cout << t << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long long MX = 3e5 + 9;
const long double pi = acos(-1);
const long long mod = 1e9 + 7;
bool cmp(int a, int b) { return a > b; }
long long po(long long a, long long b) {
if (b == 0) {
return 1;
}
long long x = po(a, b / 2);
x *= x % mod;
if (b % 2) {
x *= a % mod;
}
return x % mod;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
int n;
string s;
cin >> n;
cin >> s;
int l = s.length();
if (n == 12) {
if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else {
s[0] = '0';
}
} else if ((s[1] > '2' && s[0] == '1') || (s[0] == '0' && s[1] == '0')) {
s[1] = '1';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else {
if (s[0] > '2') {
s[0] = '0';
} else if ((s[1] >= '4' && s[0] == '2')) {
s[1] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
}
cout << s;
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MX = 3e5 + 9;
const long double pi = acos(-1);
const long long mod = 1e9 + 7;
bool cmp(int a, int b) { return a > b; }
long long po(long long a, long long b) {
if (b == 0) {
return 1;
}
long long x = po(a, b / 2);
x *= x % mod;
if (b % 2) {
x *= a % mod;
}
return x % mod;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
int n;
string s;
cin >> n;
cin >> s;
int l = s.length();
if (n == 12) {
if (s[0] > '1') {
if (s[1] == '0')
s[0] = '1';
else {
s[0] = '0';
}
} else if ((s[1] > '2' && s[0] == '1') || (s[0] == '0' && s[1] == '0')) {
s[1] = '1';
}
if (s[3] >= '6') {
s[3] = '0';
}
} else {
if (s[0] > '2') {
s[0] = '0';
} else if ((s[1] >= '4' && s[0] == '2')) {
s[1] = '0';
}
if (s[3] >= '6') {
s[3] = '0';
}
}
cout << s;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int f;
cin >> f;
string g;
cin >> g;
if (f == 12) {
if (g[0] > '1' && g[1] > '0')
g[0] = '0';
else if (g[0] > '1' && g[1] == '0')
g[0] = '1';
else if (g[0] == '1' && g[1] > '2')
g[0] = '0';
else if (g[0] == '0' && g[1] < '1')
g[0] = '1';
else
g[0] = g[0];
if (g[3] > '5')
g[3] = '5';
else
g[3] = g[3];
}
if (g[0] > '2')
g[0] = '0';
else if (g[0] == '2' && g[1] > '3')
g[1] = '3';
else
g[1] = g[1];
if (g[3] > '5')
g[3] = '5';
else
g[3] = g[3];
cout << g << endl;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int f;
cin >> f;
string g;
cin >> g;
if (f == 12) {
if (g[0] > '1' && g[1] > '0')
g[0] = '0';
else if (g[0] > '1' && g[1] == '0')
g[0] = '1';
else if (g[0] == '1' && g[1] > '2')
g[0] = '0';
else if (g[0] == '0' && g[1] < '1')
g[0] = '1';
else
g[0] = g[0];
if (g[3] > '5')
g[3] = '5';
else
g[3] = g[3];
}
if (g[0] > '2')
g[0] = '0';
else if (g[0] == '2' && g[1] > '3')
g[1] = '3';
else
g[1] = g[1];
if (g[3] > '5')
g[3] = '5';
else
g[3] = g[3];
cout << g << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
int main() {
int t, h1, h2, m1, m2, hh, mm;
scanf("%d", &t);
scanf("%1d%1d:%1d%1d", &h1, &h2, &m1, &m2);
int a, b, c, d, ans = 5, aa, bb, cc, dd;
for (int a = 0; a <= 2; a++) {
for (int b = 0; b < 10; b++) {
for (int c = 0; c < 6; c++) {
for (int d = 0; d < 10; d++) {
hh = a * 10 + b;
if (t == 24 && hh >= 24) continue;
if (t == 12 && (hh > 12 || !hh)) continue;
if (ans > (a != h1) + (b != h2) + (c != m1) + (d != m2)) {
ans = (a != h1) + (b != h2) + (c != m1) + (d != m2);
aa = a, bb = b, cc = c, dd = d;
}
}
}
}
}
printf("%d%d:%d%d\n", aa, bb, cc, dd);
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
int main() {
int t, h1, h2, m1, m2, hh, mm;
scanf("%d", &t);
scanf("%1d%1d:%1d%1d", &h1, &h2, &m1, &m2);
int a, b, c, d, ans = 5, aa, bb, cc, dd;
for (int a = 0; a <= 2; a++) {
for (int b = 0; b < 10; b++) {
for (int c = 0; c < 6; c++) {
for (int d = 0; d < 10; d++) {
hh = a * 10 + b;
if (t == 24 && hh >= 24) continue;
if (t == 12 && (hh > 12 || !hh)) continue;
if (ans > (a != h1) + (b != h2) + (c != m1) + (d != m2)) {
ans = (a != h1) + (b != h2) + (c != m1) + (d != m2);
aa = a, bb = b, cc = c, dd = d;
}
}
}
}
}
printf("%d%d:%d%d\n", aa, bb, cc, dd);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
int i, j, k, t, n, m, count = 0;
string A;
cin >> t;
cin >> A;
if (A[3] > '5') {
A[3] = '0';
}
if (t == 24) {
if (A[0] > '2') A[0] = '0';
if (A[0] == '2' && A[1] > '3') A[1] = '3';
} else if (t == 12) {
if (A[0] == '0' && A[1] == '0') A[1] = '1';
if (A[0] > '1') {
if (A[1] == '0') {
A[0] = '1';
} else {
A[0] = '0';
}
}
if (A[0] == '1' && A[1] > '2') {
A[1] = '1';
}
}
cout << A << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
int i, j, k, t, n, m, count = 0;
string A;
cin >> t;
cin >> A;
if (A[3] > '5') {
A[3] = '0';
}
if (t == 24) {
if (A[0] > '2') A[0] = '0';
if (A[0] == '2' && A[1] > '3') A[1] = '3';
} else if (t == 12) {
if (A[0] == '0' && A[1] == '0') A[1] = '1';
if (A[0] > '1') {
if (A[1] == '0') {
A[0] = '1';
} else {
A[0] = '0';
}
}
if (A[0] == '1' && A[1] > '2') {
A[1] = '1';
}
}
cout << A << endl;
return 0;
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.