正文
增加 113 行删除 13 行
123456789101112131413 行未改动28293031323334353637383940414243444518 行未改动64656667686970717273747576777879808182832 行未改动86878889909192939495969798991002 行未改动10310410510610710810911011111211311411511611711811912012112212312412512612712881 行未改动由于作者对介词搭配一窍不通,故写此程序辅助练习。比较容易魔改,拓展性(应该?)比较强。### 数据库1.空格使用`/`表示,如果真的需要显示`/`,请使用`//`;2.保存名称和代码第 26 行 `fopen` 里的名称一致,和代码放同一个文件夹即可;3.建议备份;4.目前只有 Lesson 22 的内容13 行未改动{"KeyWords"}END```### 代码(未完成):#### Windows 版```cpp//Lesson 22/46/70#include<bits/stdc++.h>#include<windows.h>#include<conio.h>using namespace std;string t[20];map<string,set<string>>mp;set<string>wds,kwds;int readi(FILE* file){char c;while(!isdigit(c=getc(file)));18 行未改动s+=c;while(checkinput(c=getc(file)))s+=c;return s;}void Prepare(){puts("Preparing...");srand(time(0));auto file=fopen("介词搭配数据库.txt","r");int n=readi(file);for(int i=0;i<n;i++){t[i]=read(file);string s;while((s=read(file))!="END"){s=Trans(s);if(!mp.count(s))wds.insert(s);mp[s].insert(t[i]);}}string s=read(file);while((s=read(file))!="END"){2 行未改动}fclose(file);system("cls");}void Test(const set<string>&st){system("cls");vector<string>v;for(auto s:st)v.push_back(s);random_shuffle(v.begin(),v.end());}void Back(){}void mian(){while(1){system("cls");puts("\2 行未改动**************************\n\n\n");puts("请输入字符选择模式:");puts("1: 所有单词随机测试");puts("2: 关键(易错)词随机测试");puts("e: 退出");string x=read(stdin);if(x=="1")Test(wds);else if(x=="2")Test(kwds);else if(x=="e")break;Back();}system("cls");}int main(){Prepare();//准备工作mian();//主程序Back();//更新数据库}```#### Linux 版```cpp//Lesson 22/46/70#include<bits/stdc++.h>using namespace std;81 行未改动123456789101112131413 行未改动2829303132333435363738394041424344454618 行未改动656667686970717273747576777879808182838485868788899091929394952 行未改动98991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891902 行未改动19319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722881 行未改动由于作者对介词搭配一窍不通,故写此程序辅助练习。~~比较容易魔改,拓展性(应该?)比较强。~~ 像依托答辩### 数据库1.空格使用`/`表示,如果真的需要显示`/`,请使用`//`;2.保存名称和代码第 26 & 134 行 `fopen` 里的名称一致,和代码放同一个文件夹即可;3.建议备份;4.目前只有 Lesson 22 的内容13 行未改动{"KeyWords"}END```### 代码:#### Windows 版```cpp//Lesson 22/46/70#include<bits/stdc++.h>#include<windows.h>#include<conio.h>using namespace std;string t[20];map<string,set<string>>mp;vector<string>mwds[20];set<string>wds,kwds;int readi(FILE* file){char c;while(!isdigit(c=getc(file)));18 行未改动s+=c;while(checkinput(c=getc(file)))s+=c;return s;}void ScreenPrint(const string &s){for(char c:s)putchar(c);}void print(const string &s,FILE* file){for(int i=0;i<s.size();i++){if(s[i]==' ')fputc('/',file);else if(s[i]=='/')fprintf(file,"//");else fputc(s[i],file);}}void Prepare(){puts("Preparing...");auto file=fopen("介词搭配数据库.txt","r");int n=readi(file);for(int i=0;i<n;i++){t[i]=read(file);string s;while((s=read(file))!="END"){s=Trans(s);if(!mp.count(s))wds.insert(s);mwds[i].push_back(s),mp[s].insert(t[i]);}}string s=read(file);while((s=read(file))!="END"){2 行未改动}fclose(file);system("cls");}bool checkword(string s,int &tot,int &Correct,int &Wrong,bool b){system("cls");printf("已测试 %d 个,正确 %d 个,错误 %d 个,正确率为 %.1lf\%\n",tot,Correct,Wrong,!tot?100:100.0*Correct/tot);int sz=mp[s].size();ScreenPrint(s),printf("(共有 %d 种搭配)\n输入exit退出\n\n",sz);set<string>userin;while(sz--){string g=read(stdin);if(g=="exit")return 1;userin.insert(g);}tot++;if(userin==mp[s]){puts("Correct"),Correct++;if(b){puts("是否移出易错词单?(y/n)");puts("注意:从下轮开始生效,本轮仍有可能出现");if(read(stdin)=="y")kwds.erase(s);}Sleep(1000);}else{Wrong++;printf("Wrong\nThe answer(s):");for(string g:mp[s])ScreenPrint(g),putchar(' ');puts("");if(!b){puts("是否加入易错词单?(y/n)");if(read(stdin)=="y")kwds.insert(s);}Sleep(1000);}return 0;}void Test(const set<string>&st,bool b){system("cls");if(st.empty()){puts("本词库为空!");Sleep(1000);return ;}vector<string>v;for(auto s:st)v.push_back(s);random_shuffle(v.begin(),v.end());puts("1:无限模式\n2:随机排列模式(不会考到重复的)\ne:退出");string x=read(stdin);BEGIN:;if(x=="1"){int tot=0,Correct=0,Wrong=0;while(1){int x=rand()%v.size();if(checkword(v[x],tot,Correct,Wrong,b))break;}}else if(x=="2"){int tot=0,Correct=0,Wrong=0;for(int i=0;i<v.size();i++)if(checkword(v[i],tot,Correct,Wrong,b))break;}else if(x=="e")return ;else goto BEGIN;}void Back(){auto file=fopen("介词搭配数据库.txt","w");int cnt=0;for(int i=0;!t[i].empty();i++)cnt++;fprintf(file,"%d\n",cnt);for(int i=0;i<cnt;i++){fprintf(file,"{\"");print(t[i],file);fputc('\"',file);for(auto s:mwds[i])fprintf(file,",\""),print(s,file),fputc('\"',file);fprintf(file,"}END\n");}fprintf(file,"\n\n");fprintf(file,"{\"KeyWords\"");for(auto s:kwds)fprintf(file,",\""),print(s,file),fputc('\"',file);fprintf(file,"}END");fclose(file);}void mian(){while(1){system("cls");puts("\2 行未改动**************************\n\n\n");puts("请输入字符选择模式:");puts("1: 所有单词随机测试");puts("2: 关键(易错)词随机测试");puts("3: 列出所有易错词");puts("e: 退出");string x=read(stdin);if(x=="1")Test(wds,0);else if(x=="2")Test(kwds,1);else if(x=="3"){system("cls");for(auto s:kwds){ScreenPrint(s),puts(":");for(auto g:mp[s])ScreenPrint(g),puts("");puts("");}system("pause");}else if(x=="e")break;Back();}system("cls");}int main(){srand(time(0));Prepare();//准备工作mian();//主程序Back();//更新数据库}```#### Linux 版 未完成(文件路径最好设成英文,不然某些编译器编译不了)```cpp//Lesson 22/46/70#include<bits/stdc++.h>using namespace std;81 行未改动