C++编程帮忙

来源:百度知道 编辑:UC知道 时间:2024/09/25 09:34:37
有一些日期,在文件abc.txt中,后面加*号的表示要加班的日期,试汇总所有每个月25号的天数,如果是加班日,则该天乘2。
abc.txt 表如下
Oct.25 2003
Oct.26.2003
Seo.12 2003*
Juy.25 2002*
App.25.2004

首先,搂住的文件格式不统一啊,怎么有的天后面有‘.’,有的没有?以下按天前后都有‘.’来做。
#include "iostream"
#include "fstream"

using namespace std;

int main()
{
int Sum = 0;
char line[20];
ifstream in("abc.txt");
while (!in.eof())
{
in>>line;
if (string(line).find(".25.") != string::npos)
{
Sum++;
if (string(line).find("*") != string::npos)
{
Sum++;
}
}
}
cout<<"天数 = "<<Sum<<endl;
return 0;
}
在VC++6和Devcpp中测试通过.

是不是仅仅25号才被汇兑?

用c写一个简单的代码供参考。
FILE *fp;
fp = fopen("abc.txt", r);
char buf[512];
int i = 0,len = 0;

while( fgets(fp, buf, 512)!=NULL)
{
len = strlen(buf);
if( buf[4]=='2' && buf[5]=='5')
{ i++;
if( buf[len-2]=='*')
i++;
}
}