zoukankan      html  css  js  c++  java
  • 帮我背单词

    要学习焚化课了,为了帮助自己背单词特地写了个代码

    目前支持的功能

    • 单词导入

    • 单词听写

    • 单词修改

    • 单词查找

    • tps:如果有人想用的话,在代码编译出的程序的文件夹内新建一个 "sjk.in" 并在里面输入 "0" 就可以了,只支持Windows

    (code)

    #include<bits/stdc++.h>
    using namespace std;
    #define rg register
    #define gc getchar
    #define rep(i, a, b) for(int i = a; i <= b; ++i)
    #include <windows.h>
    inline int read(){
    	rg char ch = gc();
    	rg int x = 0, f = 0;
    	while(!isdigit(ch)) f |= (ch == '-'), ch = gc();
    	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
    	return f ? -x : x;
    }
    namespace tx{
    	
    const int N = 1005;
    struct Node{
    	string word, part, name;
    	int value;// 默写正确次数,使用小根堆 
    	inline bool operator < (const Node &rhs) const {
    		return value < rhs.value;
    	}
    	inline void output(){ // 自带换行 
    		cout << word << " " << part << " " << name << " " << value << endl;
    	}
    	inline void put(){
    		cout << word << " " << part << " " << name << endl;
    	}
    	Node(){}
    	Node(string word, string part, string name, int value): word(word), part(part), name(name), value(value) {}
    //	1,名词,Nouns (n.) 表示人或事物的名称 box,pen,tree,apple 
    //	2,代词,Pronouns (pron.)代替名词、数词、形容词We,this,them,myself 
    //	3,形容词,Adjectives(adj.) 用来修饰名词,表示人或事物的特征 good,sad,high,short 
    //	4,数词,Numerals(num.)表示数目或顺序 one,two,first 
    //	5,动词,Verb (v.) 表示动作或状态 Jump,sing,visit 
    //	6,副词,Adverbs(adv.) 修饰动、形、副等词,表示动作特征 there,widely,suddenly 
    //	7,冠词,Articles (art.) 用在名词前,帮助说明名词所指的范围 a,an,the 
    //	8,介词,Prepositions (prep.) 用在名词或代词前,说明它与别的词的关系 in,on,down,up 
    //	9,连词,Conjunctions (conj.) 表示人或事物的名称if,because,but 
    //	10,感叹词,Interjections (int.) 代替名词、数词、形容词等 oh,hello,hi,yeah 
    //	vt.是及物动词,vt.后必须跟宾语:sing a song 
    //	vi.是不及物动词,vi.后不直接带宾语或不带宾语:jump high
    } tmp;
    struct Tf{
    	int st, id;
    	Tf(){}
    	Tf(int st, int id): st(st), id(id) {}
    }to_find[1000005];
    vector<Node> word[N], insert, all_word;
    // priority_queue<Node, vector<Node>, greater<Node> > Rand_que; //随机抽查 
    int len[N], n, m, infact_word_cnt;// n -> 天数 
    int cnt; // 总id
    int Time; // 听写时间 
    string test, wd, pt, nm;
    map<string, int> st;
    inline void init(int falg = 0){
    	freopen("sjk.in", "r", stdin);
    	n = read();
    	int vl, id;
    	rep(i, 1, n){
    		len[i] = read();
    		rep(j, 0, len[i]){
    			cin >> wd >> pt >> nm >> vl;
    			tmp =  Node(wd, pt, nm, vl);
    			word[i].push_back(tmp);
    			all_word.push_back(tmp); 
    			++cnt;
    			to_find[cnt] = Tf(i, j);
    			st[wd] = cnt;
    		}
    	}
    	if(falg == 1) cout << "导入完成,总计 " << cnt << " 个单词" << endl; 
    }
    inline void output(){
    	freopen("sjk.in", "w", stdout);
    	printf("%d
    ", n);
    	rep(i, 1, n){
    		printf("%d
    ", len[i]);
    		for(vector<Node>:: iterator it = word[i].begin(); it != word[i].end(); ++it)
    			it -> output();
    	}
    }
    inline void hyy(int n){
    	rep(i, 0, len[n]){
    		cout << "第 " << i + 1 << " 个 " << word[n][i].name << endl;
    	}
    	Sleep(Time);
    	cout << "答案:" << endl; 
    	rep(i, 0, len[n]){
    		cout << "第 " << i + 1 << " 个 "; word[n][i].put();
    	}
    	freopen("CON", "r", stdin);
    	cout << "请输入错误单词编号, 输入 0 结束" << endl;
    	int now_worn_id;
    	while((now_worn_id = read()) != 0){
    		--now_worn_id;
    		--word[n][now_worn_id].value;
    	}
    	rep(i, 0, len[n]){
    		++word[n][i].value;
    	}
    }
    inline void yyh(int n){
    	rep(i, 0, len[n]){
    		cout << "第 " << i + 1 << " 个 " << word[n][i].word << endl;
    	}
    	Sleep(Time);
    	cout << "答案:" << endl; 
    	rep(i, 0, len[n]){
    		cout << "第 " << i + 1 << " 个 "; word[n][i].put();
    	}
    	cout << "请输入错误单词编号, 输入 0 结束" << endl;
    	int now_worn_id;
    	while((now_worn_id = read()) != 0){
    		--now_worn_id; 
    		--word[n][now_worn_id].value;
    	}
    	rep(i, 0, len[n]){
    		++word[n][i].value;
    	}
    }
    inline void brtx_hyy(){
    	sort(all_word.begin(), all_word.end(), less<Node>());
    	int to = min(19, cnt - 1);
    	rep(i, 0, to){
    		cout << "第 " << i + 1 << " 个 " << all_word[i].name << endl;
    	}
    	Sleep(Time);
    	cout << "答案:" << endl; 
    	rep(i, 0, to){
    		cout << "第 " << i + 1 << " 个 "; all_word[i].put();
    	}
    	cout << "请输入错误单词编号, 输入 0 结束" << endl;
    	int now_worn_id;
    	while((now_worn_id = read()) != 0){
    		if(now_worn_id > to + 1){
    			cout << "编号错误,请从新输入" << endl;
    			continue;
    		}
    		--now_worn_id;
    		--word[to_find[st[all_word[now_worn_id].word]].st][to_find[st[all_word[now_worn_id].word]].id].value;
    	}
    	rep(i, 0, to){
    		++word[to_find[st[all_word[i].word]].st][to_find[st[all_word[i].word]].id].value;
    	}
    }
    inline void brtx_yyh(){
    	sort(all_word.begin(), all_word.end(), less<Node>());
    	int to = min(19, cnt - 1);
    	rep(i, 0, to){
    		cout << "第 " << i + 1 << " 个 " << all_word[i].word << endl;
    	}
    	Sleep(Time);
    	cout << "答案:" << endl; 
    	rep(i, 0, to){
    		cout << "第 " << i + 1 << " 个 "; all_word[i].put();
    	}
    	cout << "请输入错误单词编号, 输入 0 结束" << endl;
    	int now_worn_id;
    	while((now_worn_id = read()) != 0){
    		if(now_worn_id > to + 1){
    			cout << "编号错误,请从新输入" << endl;
    			continue;
    		}
    		--now_worn_id;
    		--word[to_find[st[all_word[now_worn_id].word]].st][to_find[st[all_word[now_worn_id].word]].id].value;
    	}
    	rep(i, 0, to){
    		++word[to_find[st[all_word[i].word]].st][to_find[st[all_word[i].word]].id].value;
    	}
    }
    inline void start_tx(){
    	cout << "请输入听写模式编号(1/2){
        1 -> 汉译英
        2 -> 英译汉
    }" << endl;
    	int now_mode_id;
    	while(true){ 
    		now_mode_id = read(); 
    		if(now_mode_id < 1 || now_mode_id > 2){
    			cout << "格式不满足要求,请输入 "1" 或 "2"" << endl;
    		}else break;
    	}
    	if(now_mode_id == 1){
    		cout << "请输入听写内容编号 (1/2/3/4){
        1 -> 今日单词
        2 -> 昨日单词
        3 -> 前日单词
        4 -> 薄弱单词
    }" << endl;	
    		while((now_mode_id = read()) < 1 || now_mode_id > 4) cout << "格式不符合要求,请从新输入" << endl;
    		cout << "请输入听写时间(秒),五分钟为 300 秒" << endl;
    		Time = read() * 1000;
    		switch(now_mode_id){
    			case 1:
    				hyy(n); break;
    			case 2:
    				if(n > 1) hyy(n - 1);
    				else cout << "并无昨日单词,已跳过" << endl; 
    				break;
    			case 3:
    				if(n > 2) hyy(n - 2);
    				else cout << "并无前日单词,已跳过" << endl; 
    				break;
    			case 4:
    				brtx_hyy(); break;
    		}
    	}else if(now_mode_id == 2){
    		cout << "请输入听写内容编号 (1/2/3/4){
        1 -> 今日单词
        2 -> 昨日单词
        3 -> 前日单词
        4 -> 薄弱单词
    }" << endl;	
    		while((now_mode_id = read()) < 1 || now_mode_id > 4) cout << "格式不符合要求,请从新输入" << endl;
    		cout << "请输入听写时间(秒),五分钟为 300 秒" << endl;
    		Time = read() * 1000;
    		switch(now_mode_id){
    			case 1:
    				if(n) yyh(n);
    				else cout << "并无今日单词,已跳过" << endl;
    				break;
    			case 2:
    				if(n > 1) yyh(n - 1);
    				else cout << "并无昨日单词,已跳过" << endl;
    				break;
    			case 3:
    				if(n > 2) yyh(n - 2);
    				else cout << "并无前日单词,已跳过" << endl;
    				break;
    			case 4:
    				brtx_yyh(); break;
    		}
    	}
    }
    //inline void start_tx(){
    //	cout << "请输入听写时间(秒),五分钟为 300 秒" << endl;
    //	Time = read() * 1000;
    //	init(1);
    //	cout << "当前为汉语听写英语" << endl;
    //	cout << "今日新背单词:" << endl;
    //	hyy(n);
    //	if(n > 1){
    //		cout << "昨日单词:" << endl;
    //		hyy(n - 1);
    //	}
    //	if(n > 2){
    //		cout << "前日单词:" << endl;
    //		hyy(n - 2);
    //	}
    //	cout << "薄弱单词:" << endl;
    //	brtx_hyy();
    //
    //	cout << "当前为英语听写汉语" << endl;
    //	cout << "今日新背单词:" << endl;
    //	yyh(n);
    //	if(n > 1){
    //		cout << "昨日单词:" << endl;
    //		yyh(n - 1);
    //	}
    //	if(n > 2){
    //		cout << "前日单词:" << endl;
    //		yyh(n - 2);
    //	}
    //	cout << "薄弱单词:" << endl;
    //	brtx_yyh();
    //}
    inline void all_out(){
    	for(Node x : all_word) x.output();	
    }
    inline void solve(string test){
    	if(test == "add"){
    		cout << "输入待添加单词个数 m " << endl; 
    		m = read() - 1;
    		cout << "输入 " << m + 1 <<" 个单词,以 "单词","词性","翻译" 为标准" << endl; 
    		rep(i, 0, m){
    			cin >> wd >> pt >> nm;
    			tmp = Node(wd, pt, nm, 0);
    			insert.push_back(tmp); 
    		}
    		init();
    		// cout << n << endl;
    		++n; len[n] = m;
    		word[n].swap(insert);
    //		for(vector<Node>:: iterator it = insert.begin(); it != insert.end(); ++it){
    //			word[n].push_back(*it);
    //			it -> id = ++cnt;
    //			all_word.push_back(*it); Not Need 
    //		}
    		cout << "添加完毕,三秒后结束" << endl;
    	}else if(test == "change"){
    		cout << "重新输入 "待修改单词","新词性","新翻译"" << endl;
    		string wd, pt, nm;
    		cin >> wd >> pt >> nm;
    		init();
    		if(!st.count(wd)){
    			cout << "词库中并无此单词,未做任何修改,三秒后结束" << endl; 
    			return;
    		}
    		word[to_find[st[wd]].st][to_find[st[wd]].id] = Node(wd, pt, nm, 0);
    		cout << "修改完毕,三秒后结束" << endl;
    	}else if(test == "start"){
    		init(1);
    		freopen("CON", "r", stdin); 
    		while(true){
    			start_tx();
    			cout <<"输入 "END" 结束听写,否则输入任意内容继续听写" << endl;
    			cin >> test;
    			if(test == "END") break; 
    		}
    		cout << "听写完毕,三秒后结束" << endl;
    	}else if(test == "find"){
    		init(1);
    		freopen("CON", "r", stdin); 
    		cout << "输入单词查找,输入大写 "END" 结束" << endl;
    		while(true){
    			cin >> wd;
    			if(wd == "END") break;
    			if(st.count(wd)){
    				word[to_find[st[wd]].st][to_find[st[wd]].id].put();
    			}else{
    				cout << "查无此词" << endl;	
    			}
    		}
    		cout << "查找完毕, 三秒后结束" << endl;
    		fclose(stdin);
    		Sleep(3000);
    		exit(0); 
    	}else{
    		cout << "命令无效,三秒后结束" << endl;
    	}
    }
    signed main(){
    	cout << "输入功能{
        1 -> "add" 添加今日单词
        2 -> "change" 修改错误单词
        3 -> "start" 开始今日听写
        4 -> "find" 查找已学词汇
    }" << endl;  
    	cin >> test;
    	solve(test);
    	output();
    	fclose(stdin); fclose(stdout);
    	Sleep(3000); 
    	return 0;
    }
    }
    signed main(){
    	return tx :: main();
    }
    
  • 相关阅读:
    centos mysql 编译安装
    vsftp配置主动模式和被动模式
    vim中选择匹配文本删除技巧
    解决zabbix图中出现中文乱码问题
    zabbix图中出现中文乱码问题
    Centos下Yum安装PHP5.5,5.6,7.0
    一款点击图片进行无限循环的jquery手风琴特效
    一款兼容IE6并带有多图横向滚动的jquery特效
    一款jQuery满屏自适应焦点图切换特效
    一款jQuery实现重力弹动模拟效果特效,弹弹弹,弹走IE6
  • 原文地址:https://www.cnblogs.com/XiaoVsun/p/13054014.html
Copyright © 2011-2022 走看看