跳到正文

个人记录

单词听写

zcEscortJ约 11 分钟
原文

这是 2026年2月3日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年11月24日
收录
2026年2月3日
更新
2026年11月22日
篇幅
约 11 分钟

版本

  1. v2当前
  2. v1

手搓单词听写代码

主要运行代码:

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

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

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

C++
#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版本(终端输入版本):

C++
#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));
    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 << "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;
}

词库文本:

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