| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
~字符串获取写下此题最长代码 如下
看了某位同学整数获取很短代码 收获很大
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
//freopen ("in.txt", "r", stdin);
int n,i,j,m,k;
char a[1][7];
scanf("%d" , &n);
while( n != 0)
{
scanf("%s" ,a[0]);
m = strlen (a[0]);
if(strcmp("00:00" , a[0]) == 0) printf("12\n");
else if( m == 4 && a[0][2] =='0'&& a[0][3] == '0')
{
k =a[0][0] - 48;
printf("%d\n" , k + 12);
}
else if ( m == 5 && a[0][3] =='0'&& a[0][4] == '0' && (a[0][0] - 48) *10 + a[0][1] - 48 >= 13 )
{
k =(a[0][0] - 48) *10 + a[0][1] - 48;
printf("%d\n" , k - 12);
}
else if ( m == 5 && a[0][3] =='0'&& a[0][4] == '0'&& (a[0][0] - 48) *10 + a[0][1] - 48 < 13 )
{
k =(a[0][0] - 48) *10 + a[0][1] - 48;
printf("%d\n" , k +12);
}
else printf("0\n");
n --;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator