题目分析:
13:00-24:00 敲钟次数为当前点钟减去12;
其余,时段敲钟次数为当前点数加上12;
解题思路:
水题。
解题代码:
#include<iostream>
#include<string>
using namespace std;
int strikeTimes(string time){
int hour=0;
if(time.length()==4){
if(time[3]!='0' || time[2]!='0'){
return 0;
}
hour+=time[0]-'0';
}else{
if(time[4]!='0' || time[3]!='0'){
return 0;
}
hour+=10*(time[0]-'0')+time[1]-'0';
}
if(13<=hour && hour<=24){
return hour-12;
}else{
return hour+12;
}
}
int main(int argc, char *argv[]){
int T;
cin>>T;
for(int i=0;i<T;i++){
string time;
cin>>time;
cout<<strikeTimes(time)<<endl;
}
return 0;
}