// 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;
}
如果问题得到解决,请点我回答左上角的采纳,谢谢