使用时可执行文件需放入同一个文件夹
#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;
}