查看POJ MOOC通过码的方式

中国大学MOOC上北大的题目做完后需要提交通过码,可以通过 右键->打开方式->记事本 打开,不过有时候通过码数量比较多,一个个打开比较麻烦,可以用标准C的文件读写,结合一些C++特性来节省时间

 1 #include <bits/stdc++.h>
 2 #include <algorithm>
 3 using namespace std;
 4 FILE *fp,*fout;
 5 int main () {
 6     cout << "Input the length of the digits:";
 7     int len;
 8     cin >> len; 
 9     
10     cout << "Input the num of fils:";
11     int n;
12     cin >> n;
13     
14     fout=fopen("result.txt","w");
15     
16     string head="acckey",dig,re;
17     char s[10];
18     
19     for (int i=1;i <= n;++i) {
20         itoa(i,s,10);
21         dig.append(len-strlen(s),'0');
22         dig.append(s);
23         re=head+dig;
24         dig.clear();
25                 
26         cout << "Reading " << re << endl;
27         fp=fopen(re.c_str(),"r");
28         char c;
29         fputc('\n',fout);
30         while (fscanf(fp,"%c",&c) != EOF) {
31             fputc(c,fout);
32         }
33         fclose(fp);
34     }
35     
36     fclose(fout);
37     cout << "Finished"; 
38 }

 

posted @ 2020-01-26 17:50  Maidzuki  阅读(381)  评论(0编辑  收藏  举报