读题需仔细
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int op1,op2;
int main(){
char c = ':';
scanf("%d%c%d",&op1,&c,&op2);
int flag = 0;
if(op1 > 12){
printf("%d:%d PM",op1-12,op2);
}
else if(op1 < 12){
printf("%d:%d AM",op1,op2);
}
else{
printf("%d:%d PM",op1,op2);
}
return 0;
}
scanf的读入时间格式
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a, b, c;
char str[N];
int main() {
scanf("%d:%d:%d%s", &a, &b, &c, str);
cout << a << b << c << str<<endl;
return 0;
}