HRBUST-1086(C语言)壮志难酬

在这里插入图片描述

字符串输入+类型转换
注意陷阱:要将小数点后面没输入的位都设置为0

AC代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <iso646.h>
#define PI acos(-1)

int main()
{
    int test_num, len, i, n, result;
    char s[100005];
    scanf("%d", &test_num);
    while(test_num--)
    {
        result = 0;
        scanf("%s%d", s, &n);
        len = strlen(s);
        for(i = 0; i < len; i++)
        {
            if(s[i] == '.')
            {
                result = s[i + n] - '0';
                break;
            }

        }
        if(n > len - 2)
            result = 0;
        printf("%d\n", result);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43005180/article/details/82945763
今日推荐