老师的福音!C++随机点名生成器

栏目: C++ · 发布时间: 6年前

内容简介:noip2018刚过,写了点小东西来愉悦身心。用途:随机点名原理:从exe文件同目录下的文档中导入人员信息(可以多重),通过rand+Hash实现,按空格键即可生成。

noip2018刚过,写了点小东西来愉悦身心。

用途:随机点名

原理:从exe文件同目录下的文档中导入人员信息(可以多重),通过rand+Hash实现,按空格键即可生成。

代码:

#include <bits/stdc++.h> 
#include <conio.h>
#include <windows.h>
static const int MAXN=101;//limit
using namespace std;
struct Information
{
    char name[MAXN];
}stu[MAXN];
bool vis[MAXN];
FILE *fp;
int num,cnt,randnum;
char ch,filename[MAXN],line[MAXN];
inline void copyright()
{
    puts("Program Name: Random Name.\n");
    Sleep(1000);
    puts("Design By:BeyondLimits.\n");
    Sleep(1000);
    puts("All rights reserved.\n");
    Sleep(1000);
}
inline void input()
{
    puts("Please input the file name of the name list.\n");
    gets(filename);
    fp=fopen(filename,"r");
    puts("Everything is ready.\n");
}
inline void work()
{
    while(fgets(line,sizeof(line)-1,fp)) if(line[0]!='\n'&&line[0]!=' ') sscanf(line,"%s\n",stu[cnt++].name);//input information
    srand(0);
    puts("Press Space to get a random name or press any other key to exit.\n");
    while((ch=getch())==' ')
    {
        randnum=rand()%cnt;
        while(vis[randnum]) randnum=rand()%cnt;
        vis[randnum]=true;
        printf("%s\n",stu[randnum].name);
        if(++num==cnt)
        {
            puts("Program has been exited.\n");
            puts("Thank you for your using.\n");
            return ;
        }
    }
}
int main()
{
    copyright();//copyright announce
    input();//input file name
    work();//main work
    return 0;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

More Eric Meyer on CSS (Voices That Matter)

More Eric Meyer on CSS (Voices That Matter)

Eric A. Meyer / New Riders Press / 2004-04-08 / USD 45.00

Ready to commit to using more CSS on your sites? If you are a hands-on learner who has been toying with CSS and want to experiment with real-world projects that will enable you to see how CSS......一起来看看 《More Eric Meyer on CSS (Voices That Matter)》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器