单词听写

· · 个人记录

手搓单词听写代码

主要运行代码:

(需在同一目录下建立名为 wordlist 的文件,并在开头输入词汇数 n , 之后每行输入 词性 英语单词 中文意思 。各组分间用空格隔开,组分中不要使用空格)

(共 20 组英译中,20 组中译英,可以更改)

Linux版本(文件输入版本):

#include<bits/stdc++.h>
using namespace std;
int n ;
struct node{
    string kind ;
    string word ;
    string chinese ;
    int val ;
}a[1000005];
bool cmp( node a , node b )
{
    if( a.val != b.val ) return ( rand()%10000 > 5000 ? a.val < b.val : a.val > b.val ) ;
    else return rand()%20000 > 1013 ;
}
signed main(){
    srand(time(0));
    ifstream file( "wordlist" ) ;
    while( 1 )
    {
        file >> n ;
        if( n < 40 || n > 300 )
        {
            cout << "Make sure you have press the number of the words in the front of the file and the number can not bigger than 300 or less than 40.\n" ;
            return 0;
        }
        for( int i = 1 ; i <= n ; i ++ )
        {
            file >> a[i].kind ;
            file >> a[i].word ;
            file >> a[i].chinese ;
            a[i].val = rand()%10000 ;
        }
        sort( a+1 , a+n+1 , cmp ) ;
        break ;
    }
    file.close() ;
    string check ;
    cout << "Please key in \"ok\" to strat the test,or key in \"not prepared\" to stop.\n" ;
    while( cin >> check ) 
    {
        if( check == "not prepared" ) return 0;
        if( check == "ok" ) break ;
        cout << "Please key in \"ok\" to strat the test\n" ;
    }
    do{
        cout << "\n\n\n\n\n\n\n\n\n\nNow I am going to give you 10 English words in total.You need to give me your ans,than I will give you the correct answer in the given file.You needs to compare them in yourself.\n" ;
        for( int i = 1 ; i <= min( n , 10 ) ; i ++ )
        {
            cout << i << ". " << a[i].kind << " " << a[i].word << "\n" ;
            while( cin >> check ) {cout << a[i].chinese << "\n" ;break ;}
        }
        cout << "Now I am going to give you 30 Chinese meaning of a word in total.You need to key in the English word,than I will compare them and give you the result.\n" ;
        for( int i = min( n+1 , 11 ) ; i <= min( 2*n , 40 ) ; i ++ )
        {
            cout << i << ". " << a[i].kind << " " << a[i].chinese << "\n" ;
            cin >> check ;
            if( check == a[i].word ) cout << "Answer right.\n" ;
            else cout << "Wrong answer!The correct answer is:" << a[i].word << ".\n" ; 
        }
        cout << "If you need to have a test again,please key in \"again\" to continue.\n" ;
        cin >> check ;
        if( check != "again" ) return 0;
        for( int i = 1 ; i <= n ; i ++ ) a[i].val = rand()%30000 ;
        sort( a+1 , a+n+1 , cmp ) ;
    }while(1) ;
    return 0;
}

Windows版本(终端输入版本)(更新颜色):

#include<bits/stdc++.h>
using namespace std;
#define RESET   "\033[0m"
#define RED     "\033[31m"
#define GREEN   "\033[32m"
#define YELLOW  "\033[33m"
#define BOLD    "\033[1m"
int n , con ;
struct node{
    string kind ;
    string word ;
    string chinese ;
    int val ;
}a[1000005] , wrong[100005] ;
bool cmp( node a , node b )
{
    if( a.val != b.val ) return ( rand()%10000 > 5000 ? a.val < b.val : a.val > b.val ) ;
    else return rand()%20000 > 1013 ;
}
signed main(){
    srand(time(0));
//    while( 1 )
//    {
        cin >> n ;
//        if( n < 40 || n > 300 )
//        {
//            cout << "Make sure you have press the number of the words in the front of the file and the number can not bigger than 300 or less than 40.\n" ;
//            return 0;
//        }
        for( int i = 1 ; i <= n ; i ++ )
        {
            cin >> a[i].kind ;
            cin >> a[i].word ;
            cin >> a[i].chinese ;
            a[i].val = rand()%10000 ;
        }
        sort( a+1 , a+n+1 , cmp ) ;
//        break ;
//    }
    string check ;
    cout << YELLOW << "Please key in \"ok\" to strat the test,or key in \"not prepared\" to stop.\n" << RESET ;
    while( cin >> check ) 
    {
        if( check == "not prepared" ) return 0;
        if( check == "ok" ) break ;
        cout << YELLOW << "Please key in \"ok\" to strat the test\n" << RESET ;
    }
    do{
        int num = 0 ;
        con = 0 ;
        cout << "Now I am going to give you 40 Chinese meaning of a word in total.You need to key in the English word,than I will compare them and give you the result.\n" ;
        for( int i = min( n+1 , 1 ) ; i <= min( n , 40 ) ; i ++ )
        {
            cout << i << ". " << a[i].kind << " " << a[i].chinese << "\n" ;
            cin >> check ;
            if( check == a[i].word ) cout << GREEN << "Answer right.\n" << RESET , num ++ ;
            else 
            {
                wrong[++con] = a[i] ;
                cout << RED << "Wrong answer!" << RESET << "The correct answer is:" << BOLD << a[i].word << ".\n" << RESET ; 
            }
        }
        cout << YELLOW << "In this part,you got " << num << "/" << min( n , 40 ) << " points\n" << RESET ;
        if( con )
        {
            cout << YELLOW << "Your answers were wrong on these words:\n" << RESET ;
            for( int i = 1 ; i <= con ; i ++ ) cout << wrong[i].kind << " " << BOLD << wrong[i].word << RESET << " " << wrong[i].chinese << "\n" ;
        }
        else
        {
            cout << GREEN << "All the answers are correct.Congratulation!\n" << RESET ;
        }
        cout << "If you need to have a test again,please key in \"again\" to continue.\n" ;
        cin >> check ;
        if( check != "again" ) return 0;
        for( int i = 1 ; i <= n ; i ++ ) a[i].val = rand()%30000 ;
        sort( a+1 , a+n+1 , cmp ) ;
    }while(1) ;
    return 0;
}

词库文本:

word list 7

list8 没搞。

word list 9

word list 10

word list 11

word list 12

word list 13

list14 保存不了

word list 15

word list 16

word list 17

word list 18

word list 21

word list 22

word list 23

word list 24

word list 25

word list 26

word list 27

word list 30

word list 31

word list 33

word list 34