日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

模拟摇号的小程序

發布時間:2023/12/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 模拟摇号的小程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

我做了一個關于搖號的小程序,它可以實現給n個人每個人一個不同的隨機數(號碼),將每個人的號碼排序然后輸出,并選取排名靠前一定數量的人作為搖中的,給予隨機數時會有漸慢的效果。

如圖:(綠色為搖中的,?紅色沒搖中)

?

使用方式

輸入兩個數 n?和?k

表示有 n?個人,?選取其中 k%?的人

代碼

#include <windows.h> #include <algorithm> #include <cstdio> #include <math.h> #include <ctime> using namespace std;enum concol {black = 0,dark_blue = 1,dark_green = 2,dark_aqua = 3, dark_cyan = 3,dark_red = 4,dark_purple = 5, dark_pink = 5, dark_magenta = 5,dark_yellow = 6,dark_white = 7,gray = 8,blue = 9,green = 10,aqua = 11,cyan = 11,red = 12,purple = 13, pink = 13, magenta = 13,yellow = 14,white = 15 };struct Peo {int Num, Score;bool operator < (Peo b){return Score > b.Score;} };HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); int n; Peo a[10050]; double UpVal; CONSOLE_CURSOR_INFO CursorInfo; COORD _GoToPos; int backcol, textcol;inline void gt(short x, short y) {--x;--y;_GoToPos = {x, y};SetConsoleCursorPosition(hOut, _GoToPos); }int GetRand() {return abs(rand() + (rand() << 17)); }void GetRandomNum(int pln) {int tmp;gt(5, pln);printf("%d", pln);for(int i=1;i<=20;++i){tmp = GetRand() % 1000000;gt(8, pln);printf("%06d", tmp);Sleep(5);}for(int i=1;i<=15;++i){tmp = GetRand() % 1000000;gt(8, pln);printf("%06d", tmp);Sleep(i*10);}a[pln].Score = tmp;a[pln].Num = pln; }inline void HideCursor() {GetConsoleCursorInfo(hOut, &CursorInfo);CursorInfo.bVisible = false;SetConsoleCursorInfo(hOut, &CursorInfo); }inline void settextcolor(concol textcolor) {textcol = textcolor;unsigned short wAttributes = ((unsigned int)backcol << 4) | (unsigned int)textcol;SetConsoleTextAttribute(hOut, wAttributes); }inline void setbackcolor(concol backcolor) {hOut = GetStdHandle(STD_OUTPUT_HANDLE);backcol = backcolor;unsigned short wAttributes = ((unsigned int)backcol << 4) | (unsigned int)textcol;SetConsoleTextAttribute(hOut, wAttributes); }int main() {HideCursor();srand(time(NULL));system("mode con cols=22 lines=50");scanf("%d%lf", &n, &UpVal);system("cls");for(int i=1;i<=n;++i){gt(5, i);printf("%d ", i);GetRandomNum(i);}sort(a+1, a+n+1);double NowVal = 0;for(int i=1;i<=n;++i){NowVal = i * 100.0 / n;gt(5, i+n+1);settextcolor(white);setbackcolor(black);printf("%d ", a[i].Num);gt(8, i+n+1);printf("%06d", a[i].Score);if(NowVal <= UpVal){setbackcolor(green);}else{setbackcolor(red);}printf(" ");}getchar();getchar();return 0; }

總結

以上是生活随笔為你收集整理的模拟摇号的小程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。