码迷,mamicode.com
首页 > 其他好文 > 详细

poj2840

时间:2015-06-18 13:16:59      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
    int n,len;
    char str[10];
    scanf("%d",&n);
    while(n--)
    {
        int tmp;
        scanf("%s",str);
        len=strlen(str);
        tmp = str[len-1] - 0+str[len-2] - 0;
        if(tmp != 0)
        {
            printf("0\n");
            continue;
        }
        else
        {
            if(len == 4)
                tmp = str[len-4]-0;
            else
                tmp = str[len-4] - 0 + (str[len-5] - 0)*10;
            if(tmp <= 12)
                printf("%d\n",tmp+12);
            else
                printf("%d\n",tmp-12);
        }
    }
    return 0;
}
View Code
技术分享
//2840
#include<stdio.h>
main()
{
    int t,a,b;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d:%d",&a,&b);
        b?puts("0"):printf("%d\n",a>12?a-12:a+12);
    }
}
View Code

一开始的想法是因为输入的??:??所以以为只能把他作为串来放进数组,可是大神用了13行就写出来了,scanf("%d:%d",&h,&m)

 

poj2840

标签:

原文地址:http://www.cnblogs.com/gabygoole/p/4585288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!