poj2840

#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)

 

你可能感兴趣的:(poj)