版本比较
新概念2 介词搭配练习程序
正文
增加 199 行删除 11 行
123345678910101112131413 行未改动28293031323233343536373839404142434445469 行未改动565758595860616263646566676869707172737475767778798081826983848586878889907891929394952 行未改动989910010189102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166951671681691701711721731741751761771781791801811821831841851861871881891902 行未改动193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300113301302303116304305118306307308309由于作者对介词搭配一窍不通,故写此程序辅助练习。
比较容易魔改,拓展性(应该?)比较强。~~比较容易魔改,拓展性(应该?)比较强。~~ 像依托答辩
### 数据库
1.空格使用`/`表示,如果真的需要显示`/`,请使用`//`;
2.保存名称和代码第 26 行 `fopen` 里的名称一致,和代码放同一个文件夹即可;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)));9 行未改动 else i++,res+='/'; } return res;}bool checkinput(char c){return isalpha(c) || c=='/';}bool checkinput(char c){return isalpha(c) || c=='/' || isdigit(c);}string read(FILE* file){ char c; while(!checkinput(c=getc(file))); string s; 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..."); 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]); mwds[i].push_back(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){
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(){}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;string t[20];map<string,set<string>>mp;set<string>wds,kwds;int readi(FILE* file){ char c; while(!isdigit(c=getc(file))); int res=c^48; while(isdigit(c=getc(file)))res=(res<<3)+(res<<1)+(c^48); return res;}string Trans(const string &x){ string res; for(int i=0;i<x.size();i++){ if(x[i]!='/')res+=x[i]; else if(i==x.size()-1 || x[i+1]!='/')res+=' '; else i++,res+='/'; } return res;}bool checkinput(char c){return isalpha(c) || c=='/' || isdigit(c);}string read(FILE* file){ char c; while(!checkinput(c=getc(file))); string s; s+=c; while(checkinput(c=getc(file)))s+=c; return Trans(s);}void Prepare(){ puts("Preparing..."); srand(time(0)); auto file=fopen("preps.txt","r"); int n=readi(file); for(int i=0;i<n;i++){ t[i]=read(file); string s; while((s=read(file))!="END"){ if(!mp.count(s))wds.insert(s); mp[s].insert(t[i]); } } string s=read(file); while((s=read(file))!="END"){ if(!kwds.count(s))kwds.insert(s); } fclose(file); system("clear");}void Test(const set<string>&st){ system("clear"); vector<string>v; for(auto s:st)v.push_back(s); random_shuffle(v.begin(),v.end());}void Back(){}void mian(){ while(1){ system("clear"); puts("\**************************\n\***欢迎来到介词搭配练习***\n\**************************\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"); system("clear");}int main(){ Prepare();//准备工作 Prepare();//准备工作 mian();//主程序 Back();//更新数据库 Back();//更新数据库}
```