这题这么输入一或两个数字来判断类型,怎么做啊?

图片说明

// Q713808.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "stdio.h"
#include "stdlib.h"

typedef struct
{
    float t;
    float d;
    void * next;
} LinkedList;

int main()
{
    int state = 0;
    LinkedList *head, *p;
    head = p = (LinkedList *)malloc(sizeof(LinkedList));
    p->d = 0.0f;
    p->t = 0.0f;
    float f = 0.0f;
    float base = 1.0;
    char ch = 0;
    char pch = ch;
    while (true)
    {
        ch = getchar();
        if (pch == '\n' && ch == '\n') break;
        pch = ch;
        switch (state)
        {
        case 0:
        case 2:
            if (ch >= '0' && ch <= '9')
            {
                f *= 10;
                f += (int)(ch - '0');
            }
            if (ch == '.')
            {
                if (state == 0) state = 1; else state = 3;
            }
            if (ch == ' ') 
            {
                p->d = f;
                f = 0.0;
                base = 1.0;
                state = 2;
            }
            if (ch == '\n') 
            {
                p->t = f;
                f = 0.0;
                base = 1.0;
                state = 0;
                p->next = (LinkedList *)malloc(sizeof(LinkedList));
                p = (LinkedList *)p->next;
                p->d = 0.0f;
                p->t = 0.0f;
                p->next = NULL;
            }
            break;
        case 1:
        case 3:
            if (ch >= '0' && ch <= '9')
            {
                base /= 10.0;
                f += base * (int)(ch - '0');
            }
            if (ch == ' ') 
            {
                p->d = f;
                f = 0.0;
                base = 1.0;
                state = 0;
            }
            if (ch == '\n') 
            {
                p->t = f;
                f = 0;
                base = 1.0;
                state = 0;
                p->next = (LinkedList *)malloc(sizeof(LinkedList));
                p = (LinkedList *)p->next;
                p->d = 0.0f;
                p->t = 0.0f;
                p->next = NULL;
            }
            break;
        }
    }
    p = head;
    while (p->next != NULL)
    {
        if (p->d == 0.0f && int(p->t) - (p->t) <= 0.0001 && int(p->t) - (p->t) >= -0.0001)
            p->t = (float)((int)(p->t) - 1);
        if (p->d != 0.0f)
            printf("%.2f\n", 2.0 * p->d + 0.2 * p->t);
        else
            printf("%d\n", int(p->t));
        p = (LinkedList *)p->next;
    }
    return 0;
}


图片说明

如果问题得到解决,请点我回答左上角的采纳,谢谢

 #include<stdio.h>
#pragma warning(disable:c4996)
int main()
{
    int count=0;    //行数
    scanf("%d",&count);
    float time=0,miles=0;   //骑行时间和骑行距离
    for (int i = 0; i < count; i++) {
        scanf("%f", &time);
        if (getchar() == ' ') {
            scanf("%f", &miles);
            printf("%f\n\n",time*2+0.2*miles);
        }
        else {
            if (time <= 1)
                printf("0\n\n");
            else
            printf("%d\n\n",(int)time);
        }
    }
    return 0;
}

效果图