d018.
字串讀取練習
| From: [210.186.53.165] |
發表日期
:
2014-05-21 08:33
#include<stdio.h>
#include<string.h>
#define numb 50
float Oldnum1=0.0,Evennum1=0.0;
void OnE(char str2[],int num);
void count1(char str2[],int num1,int num2,int flag);
int main()
{
int i,cnt1=0;
char str1[numb],str2[numb]={0};
while(gets(str1) != NULL)
{
int num1=0;
for(i=0;i <= strlen(str1);i++)
{
str2[num1] = str1[i];
num1++;
if(str1[i] == ' ' || str1[i] == '\0')
{
OnE(str2,cnt1);
cnt1=-1;
num1 = 0;
}
cnt1++;
}
printf("%g\n",Oldnum1 -= Evennum1);
Oldnum1=0.0,Evennum1=0.0;
}
return 0;
}
void OnE(char str2[],int cnt1)
{
int i,j,num1=0,cnt2=0,cnt3=0,flag=0,len=cnt1;
for(i=0,j=0;str2[i] != ':';i++,j++);
for(i=0;i < j;i++)
{
if(cnt3 == 1)
cnt2 *= 10;
cnt2 += (str2[i] % 48);
cnt3 = 1;
}
i++;
if(cnt2 % 2 != 0)
{
flag = 1;
count1(str2,i,len,flag);
}
else
count1(str2,i,len,flag);
}
void count1(char str2[],int num1,int num2,int flag)
{
int i,cnt2=0;
float cnt1=0.0,chu=10;
for(i=num1;str2[i] != '.' && str2[i] != ' ' && str2[i] != '\0';i++)
{
if(cnt2 == 1)
cnt1 *= 10;
cnt1 += (str2[i] % 48);
cnt2 =1;
}
if(str2[i] == '.')
{
i++;
for(;i < num2;i++)
cnt1 += (str2[i] % 48) / chu;
chu *= 10;
}
if(flag == 1)
Oldnum1 += cnt1;
else
Evennum1 += cnt1;
}
程式里是哪一邊有問題啊? 不清楚RE的問題是什麽