百度之星程序设计大赛 D题 注意时间就行了不难
View Code
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int main() 6 { 7 int ncases,sum,a,i,len,k; 8 char s[8]; 9 10 scanf("%d",&ncases); 11 while(ncases--) 12 { 13 scanf("%s",s); 14 len = strlen(s); 15 for(i=0; i<len; i++) 16 { 17 if(s[i]==':') 18 k = i; 19 } 20 sum = 0; 21 if(k == len-2) 22 { 23 if(s[k+1]=='0') 24 { 25 for(i=0; i<k; i++) 26 { 27 sum = sum*10 + (s[i]-'0'); 28 } 29 sum += 12; 30 } 31 32 } 33 else 34 { 35 if(s[k+1]=='0'&&s[k+2]=='0') 36 { 37 for(i=0; i<k; i++) 38 { 39 sum = sum*10 + (s[i]-'0'); 40 } 41 sum += 12; 42 } 43 44 } 45 if(sum > 24) sum = sum%24; 46 printf("%d\n",sum); 47 } 48 49 return 0; 50 }