自动生成做题记录

使用时可执行文件需放入同一个文件夹

#include<bits/stdc++.h>
using namespace std;
//struct tm           /*c++中已定义 */
//{
//    int tm_sec;     /* seconds after the minute - [0,59] */
//    int tm_min;     /* minutes after the hour - [0,59] */
//    int tm_hour;    /* hours since midnight - [0,23] */
//    int tm_mday;    /* day of the month - [1,31] */
//    int tm_mon;     /* months since January - [0,11] */
//    int tm_year;    /* years since 1900 */
//    int tm_wday;    /* days since Sunday - [0,6] */
//    int tm_yday;    /* days since January 1 - [0,365] */
//    int tm_isdst;   /* daylight savings time flag */
//};
string username="你的名字";
bool check(string s)
{
	string t="未命名";
	for (int i=0;i<s.length()-t.length();)
	{
		int flag=1;
		for (int j=0;j<t.length();j++)
		{
			if (s[i+j]!=t[j])
			{
				flag=0;
				break;
			}
		}
		if (flag) return false;
		if (s[i]<0) i+=2;
		else i+=1;
	}
	return true;
}
string s[1005];
int tot=0;
void read_name(string name)
{
	ifstream ifs;
	ifs.open(name.c_str());
	string s_in;
	while (getline(ifs,s_in))
	{
		if (check(s_in))
		{
			s[++tot]=s_in;
			cout<<"已获取:"<<s_in<<endl;
		}
		else
		{
			cout<<"自动去除:"<<s_in<<endl;
		}
	}
	ifs.close();
	return;
}
string change_time(int x)
{
	char hour[20]="",minute[20]="",second[20]="";
	if (x>=3600) sprintf(hour,"%d时",x/3600);
	x%=3600;
	if (x>=60) sprintf(minute,"%d分",x/60);
	if (x>=1) sprintf(second,"%d秒",x);
	string s1=hour,s2=minute,s3=second;
	return s1+s2+s3;
}
signed main()
{
	int start_time=time(0);
	time_t nowtime;
	struct tm* p;;
	time(&nowtime);
	p = localtime(&nowtime);
	char tim[1005];
	sprintf(tim,"%d年%d月%d日",(p->tm_year)+1900,(p->tm_mon)+1,p->tm_mday);
	string name=username+",做题记录"+tim+".txt";
	system(("dir /b *.cpp > "+name).c_str());
	read_name(name); 
	ofstream ofs;
	ofs.open((name).c_str());
	ofs<<tim<<"共完成"<<tot<<"道题目"<<endl<<"-------------------------------------------------"<<endl;
	for (int i=1;i<=tot;i++)
	{
		ofs<<s[i]<<endl;
	}
	ofs<<"-------------------------------------------------"<<endl;
	ofs.close();
	printf("处理完成,现在时间:%d年%d月%d日",(p->tm_year)+1900,(p->tm_mon)+1,p->tm_mday);
	printf("%02d时%02d分%02d秒\n",p->tm_hour,p->tm_min,p->tm_sec);
	int end_time=time(0);
	cout<<"共耗时"<<change_time(end_time-start_time+1)<<endl;
	system("pause");
	return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值