C++程序题~~关于加班的~~难题~

来源:百度知道 编辑:UC知道 时间:2024/05/12 03:30:48
讲话救急啊~~~C++作业题~~,请求各位C++高手帮帮忙啊~~
有一些日期,在文件abc.txt中,后面加*号表示要加班的日期,试汇总所有每个25号的天数,如果是加班日,则该天乘2.
abc.txt文件内容是:
Oct.25 2003
Oct.26 2003
Sept.12 2003*
Juy.25 2002
App.25 2004

#include<stdio.h>
#include<string.h>

int main()
{
freopen("D:\\date.txt","r",stdin);
char s[100];
int len,num,i,t;
num=0;
while(gets(s))
{
len=strlen(s);
i=0;
while(s[i]!='.')
i++;
t=0;
for(i++;s[i]!=' ';i++)
{
t=t*10+s[i]-'0';
}
if(t==25)
{
if(s[len-1]=='*')
{
num+=2;
}
else
{
num++;
}
}
}
printf("The number of days: %d\n",num);
return 0;
}

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char* argv[])
{
fstream f;
string a,b;
int n=0,k;
f.open("abc.txt",ios::in);
while(f>>a>>b)
{
if(a[a.size()-2]=