抽奖程序

来抽小优秀吧~~~

Code

  1 #include<iostream>//标准流 
  2 #include<ctime>//生成随机种子 
  3 #include<algorithm>//用于随机打乱数列 
  4 #include<vector>//保存历史 
  5 #include<windows.h>//暂停 设置颜色 
  6 #include<fstream>//文件流 
  7 #include<cstring>//字符串 快读 
  8 #define IL inline//内联函数加速调用 
  9 using namespace std;
 10 
 11 
 12 
 13 int mode=2;
 14 /*
 15 0:Complete mode
 16 1:Developer mode
 17 2:Test mode
 18 */
 19 
 20 int TIME=0;//字符输出间隙(毫秒)
 21 
 22 const int total[5]={21,6,5,5,5};
 23 int stats[5];
 24 
 25 const int a=10,b=11,c=12,d=13,e=14,f=15;//颜色 
 26 
 27 int array[43];//存数量 
 28 
 29 bool book[43];//记录是否查询 
 30 
 31 int tot=0;
 32 
 33 bool flag;
 34 
 35 vector<int> history;
 36 vector<string> sentence;
 37 
 38 IL void SetColor(unsigned short BackGroundColor,unsigned short ForeColor)
 39 {
 40     HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);  
 41     SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));  
 42 }
 43 
 44 IL void gotoxy(int x, int y)
 45 {
 46     COORD pos;
 47     pos.X = x - 1;
 48     pos.Y = y - 1;
 49     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
 50 }
 51 
 52 IL void sp(const char* str,int sleeptime=TIME)//SlowPrint 
 53 {
 54     int i=0;
 55     while(str[i]!='')   
 56     {
 57         printf("%c", str[i]);
 58         if(str[i]=='*') Sleep(sleeptime*30);//*则延长至30倍时间 
 59         if(str[i]=='
'||str[i]==','||str[i]=='.') Sleep(sleeptime);//特殊符号再延长一倍 
 60         if(str[i]=='') Sleep(sleeptime*4);
 61         Sleep(sleeptime);
 62         i++;
 63     }
 64 }
 65 
 66 IL void sp(string str,int sleeptime=TIME)
 67 {
 68     int i=0;
 69     while(str[i]!='')   
 70     {
 71         printf("%c", str[i]);
 72         if(str[i]=='*') Sleep(sleeptime*30);//*则延长至30倍时间 
 73         if(str[i]=='
'||str[i]==','||str[i]=='.') Sleep(sleeptime);//特殊符号再延长一倍 
 74         if(str[i]=='') Sleep(sleeptime*4);
 75         Sleep(sleeptime);
 76         i++;
 77     }
 78 }
 79 
 80 IL void spsp(const char* str, int sleeptime=1)//freestyle的SlowPrint
 81 {
 82     int i=0;
 83     while(str[i]!='')   
 84     {      
 85         printf("%c", str[i]);
 86         Sleep(sleeptime);
 87         i++;
 88     }
 89 }
 90 
 91 //签名 
 92 IL void myname_small(int x,int y)
 93 {
 94     SetColor(15,0);
 95     //H
 96     gotoxy(x,y);
 97     cout<<"■■■";
 98     for(int i=y+1;i<y+3;i++){gotoxy(x,i);cout<<"■  ■";}
 99     //S 
100     gotoxy(x+4*2,y);cout<<"";
101     gotoxy(x+5*2,y+1);cout<<"";
102     gotoxy(x+6*2,y+2);cout<<"";
103     gotoxy(x+7*2,y+1);cout<<"";
104     gotoxy(x+8*2,y);cout<<"";
105     //H
106     gotoxy(x+10*2,y);
107     cout<<"■■■";
108     for(int i=y+1;i<y+3;i++){gotoxy(x+10*2,i);cout<<"■  ■";}
109 }
110 
111 //隐藏光标 
112 HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
113 COORD coord;
114 IL void hide()
115 {
116     CONSOLE_CURSOR_INFO cursor_info={1,0};
117     SetConsoleCursorInfo(hout, &cursor_info);
118 }
119 
120 IL void freestyle()
121 {
122     
123     //spsp("                ********
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############");
124     SetColor(f,c);
125     spsp("              ...........................              
               .............**..........               
            ......**/@@@@@@@@@@@@@@]*.......           
        .  .....,/@@@[`*.*.**.****\@@@\*....           
       .....**/@@[*....... .. ......*,\@@`*......      
       ....*,@@[**......        .....***O@@`.....      
       ..**/@^..........       ...........\@\*...      
       .*,@@**..........       ............=@\...      
. ......,@@`.............      ......*.....*=@@*. ..  .
.   ....=@^*...*优*`*优*       ...秀*秀*秀..*@@\..    .
. .....*@@*...,优/优/@O*..    ..*@秀@秀@@\*..,@@*....  
. .....=@^**.=优@优@@优^..    ..*\O秀@秀O`*..*\@*.. ...
 .. ...=@^..*,优\O@优^**.     ..*\秀@秀@/`...*@@*......
... ...=@^..**/@O优@=@o@^.     ..**/@/*@秀^...*@@*.....
.......*@@*...=@/`**[[[*.     ..*@[*.=@@/*...,@@*.  .  
. ......\@`.*............     ..............*@@^.. .  .
       .*@@`*...........       ............*=@/*.      
        .,@@^....      .           .. ....*=@^*..      
       ...*\@^*.....           ..........*/@/*...      
       ...**=@@`....  ..        . ....**/@@`*...       
       ......*\@@\****...............*/@@`*......      
     ........**.*\@@@]**........*,/@@@/**.*.....       
       ............*[\@@@@@@@@@@@@[`*...........       
       ................*.*.***..................       
        . .........................  .. .   .          
");
126     Sleep(1500); 
127     system("cls");
128     gotoxy(26,11);
129     SetColor(f,c);
130     sp("欢 迎 来 抽 小 优 秀 !
",30);
131     Sleep(1000);
132     gotoxy(20,12);
133     sp("祝同学们抽奖大吉大利,小优秀红红火火!",30);
134     Sleep(1000);
135     gotoxy(35,13);
136     sp("Desigh and code by SOAF(send-off-a-friend)折柳",15);
137     myname_small(40,20);
138     Sleep(1000);
139     system("cls");
140 }
141 
142 IL void init(){//初始化 
143     memset(book,0,sizeof(book));
144     memset(stats,0,sizeof(stats));
145     tot=0;
146     flag=1;
147     //由于限定了小优秀的个数,所以必须先定量生成序列 
148     int now=0;
149     for(int i=0;i<=4;i++)
150         for(int j=1;j<=total[i];j++)
151             array[++now]=i;
152     random_shuffle(array+1,array+43);//STL打乱 
153     //for(int i=1;i<=42;i++) cout<<array[i]<<endl;//用于测验有没有打乱 
154     sentence.push_back("祝你数小优秀数到手抽筋!!!");
155     sentence.push_back("愿你万事如意,努力有成功,买卖有收获,愿你发小优秀在今朝,兴小优秀在此刻!!!");
156     sentence.push_back("送你一个小优秀篮,低层装满小优秀;中间呈放小优秀;四周堆满小优秀;上面铺满了小优秀!!!");
157     sentence.push_back("祝抽奖大吉大利,小优秀红红火火!!!");
158     sentence.push_back("一份付出有大收获,一份繁忙有小优秀!!!");
159     sentence.push_back("小优秀茂盛达三江,江深水远凭你游,游到龙宫,再现王者风采.祝福抽奖大吉,秀到成功!!!");
160     sentence.push_back("你定能小优秀兴隆小优秀滚滚,宏图大展蒸蒸日上!!!");
161     sentence.push_back("吉祥如意罩着,招财进宝护着,财神爷看着,各路神仙把场捧着,小优秀不得才怪!!!");
162     sentence.push_back("恭祝小优秀滚滚达三江,小优秀兴隆通四海!!!");
163     sentence.push_back("愿你小优秀兴隆,小优秀广进,和气生小优秀,万事如小优秀,小优秀不断,开心走远!!!");
164     sentence.push_back("祝你得小优秀似春笋,一节更比一节高!!!");
165     sentence.push_back("祝你小优秀如海潮,后浪推着前浪跑,一浪更比一浪强!!!");
166     sentence.push_back("绽放花朵送小优秀,鞭炮响亮送小优秀,横幅红字送小优秀,崭新面貌迎小优秀!!!");
167     sentence.push_back("看你一脸福相,我就知道你是得小优秀的好材料!一双明目,照亮“小优秀”途和未来;一张笑脸,喜迎八方小优秀来;一只玉手,巧似福猫招小优秀快");
168     sentence.push_back("祝你小优秀兴隆,小优秀广进如滔滔江水连绵不绝!!!");
169     sentence.push_back("祝你小优秀不断,如黄河泛滥一发不可收拾!!!");
170     sentence.push_back("祝你小优秀大吉喜无边,小优秀滚滚伴君来;小优秀兴隆万事顺,小优秀通四海源贯南北;小优秀兴旺万事顺,繁荣昌盛小优秀滚滚来!!!");
171     sentence.push_back("奉天承运,皇帝诏曰:朕命人所管天象,发现将遇小优秀天气,点缀春雨,此乃吉兆,把握好此契机,你的小优秀一定兴隆,蒸蒸日上!!!");
172     //sentence.push_back("");
173 }
174 
175 IL bool judge(string str)
176 {
177     if(str=="yes"||str=="y"||str=="YES"||str=="Y"||str=="ok"||str=="OK") return 1;
178     return 0;
179 }
180 
181 IL bool judge()
182 {
183     string t;
184     cin>>t;
185     return judge(t);
186 }
187 
188 IL void egg(int num);//鸭子下蛋了…… 
189 
190 IL int read()//快读 防输入卡bug 指令 
191 {
192     string str;
193     int ans=0;
194     cin>>str;
195     //instruction
196     if(str=="help")
197     {
198         cout<<"指令如下
";
199         cout<<"save		将所有数据(学号、小优秀个数、状态)保存至save.txt
";
200         cout<<"show		展示所有人的小优秀个数
";
201         cout<<"list		展示所有人是否已经抽过
";
202         cout<<"show&list	上面两个都展示
";
203         cout<<"history		输出历史记录
";
204         cout<<"empty		清空所有人的状态
";
205         cout<<"refresh		刷新所有人小优秀的个数
";
206         cout<<"init		全部初始化
";
207         cout<<"cls		清空屏幕
";
208         cout<<"break		结束抽奖
";
209         cout<<"over		同上
";
210         cout<<"STATS		统计信息
";
211         cout<<"main		重启
"; 
212         return 0; 
213     }
214     if(str=="save")//保存至save.txt 
215     {
216         history.push_back(-1); 
217         ofstream fout("save.txt",ios::out/*|ios::binary|ios::app*/);
218         for(int i=1;i<=42;i++) fout<<i<<" "<<array[i]<<" "<<book[i]<<endl;
219         return 0;
220     }
221     if(str=="show")//展示所有人的小优秀个数 
222     {
223         history.push_back(-2); 
224         cout<<"学号	个数
";
225         for(int i=1;i<=42;i++) cout<<i<<"	"<<array[i]<<endl;
226         return 0;
227     }
228     if(str=="list")//展示所有人是否已经抽过  
229     {
230         history.push_back(-3); 
231         cout<<"学号	状态
";
232         for(int i=1;i<=42;i++) cout<<i<<"	"<<(book[i]?"Yes":"No")<<endl;
233         return 0;
234     }
235     if(str=="show&list")//将上面两个都展示 
236     {
237         history.push_back(-4); 
238         cout<<"学号	个数	状态
";
239         for(int i=1;i<=42;i++) cout<<i<<"	"<<array[i]<<"	"<<(book[i]?"Yes":"No")<<endl;
240         return 0;
241     }
242     if(str=="history")//输出历史记录
243     {
244         for(unsigned int i=0;i<history.size();i++)
245         {
246             cout<<i<<"	";
247             if(history[i]<0) cout<<"Order:";
248             if(history[i]<=42&&history[i]>0){
249                 cout<<"inquiry "<<history[i]<<endl;
250                 continue;
251             }
252             if(history[i]<=-100){
253                 cout<<"TIME "<<-history[i]-100<<endl;
254                 continue;
255             }
256             switch(history[i]) {
257                 case 0:{
258                     cout<<"error instruction
";
259                     break;
260                 }
261                 case -1:{
262                     cout<<"save
";
263                     break;
264                 }
265                 case -2:{
266                     cout<<"show
";
267                     break;
268                 }
269                 case -3:{
270                     cout<<"list
";
271                     break;
272                 }
273                 case -4:{
274                     cout<<"show&list
";
275                     break;
276                 }
277                 case -5:{
278                     cout<<"history
";
279                     break;
280                 }
281                 case -6:{
282                     cout<<"empty
";
283                     break;
284                 }
285                 case -7:{
286                     cout<<"cancel previous
";
287                     break;
288                 }
289                 case -8:{
290                     cout<<"refresh
";
291                     break;
292                 }
293                 case -9:{
294                     cout<<"cls
";
295                     break;
296                 }
297                 case -10:{
298                     cout<<"break(gameover)
";
299                     break;
300                 }
301                 case -11:{
302                     cout<<"init
";
303                     break;
304                 }
305                 case -12:{
306                     cout<<"STATS
";
307                     break;
308                 }
309                 case -13:{
310                     cout<<"mode ?
";
311                     break;
312                 }
313                 case -14:
314                 case -15:
315                 case -16:{
316                     cout<<"mode "<<-13-history[i]-1<<endl;
317                     break;
318                 }
319                 case -17:{
320                     cout<<"main
";
321                     break;
322                 }
323                 case -99:{
324                     cout<<"TIME error
";
325                     break;
326                 }
327                 case -18:{
328                     cout<<"sentence
";
329                     break;
330                 } 
331                 case -19:{
332                     cout<<"message
";
333                     break;
334                 }
335                 default:{
336                     cout<<"Undefined
";
337                     break;
338                 }
339             }
340         } 
341         if(history.empty()) cout<<"No history
";
342         else cout<<history.size()<<" in total
";
343         history.push_back(-5); 
344         return 0;
345     } 
346     if(str=="empty")//清空状态 
347     {
348         history.push_back(-6); 
349         cout<<"Are you sure you want to clear the list?(y/n)
";
350         if(judge()) memset(book,0,sizeof(book)),tot=0;
351         else cout<<"Instruction cancel
",history.push_back(-7);
352         return 0;
353     }
354     if(str=="refresh")//刷新小优秀的个数 
355     {
356         history.push_back(-8); 
357         cout<<"Are you sure to refresh the number of small excellent?(y/n)
";
358         if(judge()) random_shuffle(array+1,array+43);//STL打乱 
359         else cout<<"Instruction cancel
",history.push_back(-7);
360         return 0;
361     }
362     if(str=="init")//初始化 
363     {
364         history.push_back(-11);
365         cout<<"Are you sure you want to initialize?(y/n)";
366         if(judge()) init();
367         else cout<<"Instruction cancel
",history.push_back(-7);
368         return 0;
369     }
370     if(str=="cls")
371     {
372         history.push_back(-9); 
373         return -2;
374     } 
375     if(str=="break"||str=="over")
376     {
377         history.push_back(-10); 
378         tot=42;
379         flag=1;
380         return 0;
381     }
382     if(str=="STATS")
383     {
384         history.push_back(-12);
385         cout<<"优秀		总数		已获得		剩余
";
386         for(int i=0;i<=4;i++)
387             cout<<i<<"		"<<total[i]<<"		"<<stats[i]<<"		"<<total[i]-stats[i]<<endl;
388         return 0;
389     }
390     if(str=="mode")
391     {
392         int t;
393         cin>>t;
394         if(t<3&&t>=0) mode=t,history.push_back(-13-t-1);
395         else history.push_back(-13);
396         return 0;
397     }
398     if(str=="main")
399     {
400         history.push_back(-17);
401         return -3;
402     }
403     if(str=="TIME")
404     {
405         int t;
406         cin>>t;
407         if(t<=200&&t>=0) TIME=t,history.push_back(-100-t);
408         else history.push_back(-99);
409         return 0;
410     }
411     if(str=="sentence")
412     {
413         sp(sentence[rand()%sentence.size()]);
414         history.push_back(-18);
415         return 0;
416     }
417     if(mode==2&&str=="message")
418     {
419         cout<<"请开始留言,并以‘#’结束
";
420         ofstream mout("message.txt",ios::out|ios::app);
421         getchar();
422         char ch=getchar();
423         mout<<time(0)<<endl;
424         while(ch!='#'){
425             mout<<ch;
426             ch=getchar();
427         }
428         mout<<endl;
429         cout<<"留言成功!
";
430         return 0;
431     }
432     for(unsigned int i=0;i<str.size();i++)//这才是读取...... 
433     {
434         if(str[i]>'9'||str[i]<'0'){
435             history.push_back(0);
436             return -1;
437         }
438         ans=ans*10+str[i]-'0';
439     }
440     history.push_back(ans);
441     if(ans>=43||ans<=0) return -1;
442     return ans; 
443 }
444 
445 int main()
446 {
447     system("color f0");
448     
449     if(mode!=1)//非开发者模式 
450     {
451         TIME=30;
452         hide();
453         freestyle();
454     }
455     if(mode==0){
456         system("title 元旦快乐!");
457         sp("说明:本抽奖程序自带检查,支持指令。输入help以查看指令。
重新打开本程序后,数据将会刷新。
所以即使不小心关了,只要“确认读取上次的记录”即可
",10);
458         sp("大家应该都不会输错学号吧?输错了也没关系就是了           
",10);
459         sp("感谢大家测试bug!
祝大家小优秀兴隆,小优秀广进如滔滔江水连绵不绝!!!
",10);
460     }
461     if(mode==1){
462         TIME=0;
463         system("title Developer mode"); 
464         sp("说明:
现在是Developer mode
Order:
save
show
list
show&list
history
empty
refresh
init
cls
break(over)
STATS
参数:
语速快(间隙=0ms)
鸭子下蛋
封面关闭
光标显示
允许输入指令
");
465     }
466     if(mode==2){
467         system("title Test mode");
468         sp("说明:
现在是测试模式。
欢迎测试bug
参数:
语速正常(间隙=30ms)
没有鸭子下蛋
封面开启
光标已隐藏
允许输入指令
");
469         sp("在输入学号页面输入help以寻求指令帮助
"); 
470     }
471     system("pause");
472     system("cls");
473     
474     //开始 
475     
476     system("color f0");
477     
478     srand(time(NULL));
479     
480     init();
481     
482     cout<<"是否读取上次的记录?(yes/no)
";
483     
484     if(judge()){
485         ifstream fin("save.txt",ios::in);
486         int n;
487         for(int i=1;i<=42;i++) fin>>n>>array[i]>>book[i];
488     }
489     else{
490         ofstream fout("save.txt",ios::out/*|ios::binary|ios::app*/);
491         for(int i=1;i<=42;i++) fout<<i<<" "<<array[i]<<" "<<book[i]<<endl;
492         cout<<"已自动保存
";
493         Sleep(500);
494     }
495     system("cls");
496     
497     tot=0;
498     int num;
499     sp("开  始  抽  奖!!!
",TIME*2);
500     while(true)
501     {
502         SetColor(f,0);
503         if(tot>=42&&flag)
504         {
505             cout<<"所有人都抽完了,是否结束?(y/n)
不再询问这个问题(stop/s)
";
506             string t;cin>>t;
507             if(judge(t)) break;
508             if(t=="stop"||t=="s") flag=0;
509         }
510         
511         if(mode==2) cout<<"如果你对这个程序有什么问题,欢迎留言!
留言方式:输入message
"; 
512         cout<<"输入您的学号:";
513         
514         num=read();
515         
516         if(num==-2){//cls
517             system("cls");
518             cout<<"Instruction executed successfully";
519             for(int i=0;i<33;i++) cout<<" ",Sleep(50);
520             continue; 
521         }
522         if(num==-1){ 
523             SetColor(a,0);
524             cout<<"别瞎输,OK?


";
525             Sleep(200);
526             continue;
527         } 
528         if(num==-3){
529             system("cls");
530             main();
531             return 0;
532         }
533         if(num==0){
534             cout<<"Instruction executed successfully
";
535             continue;
536         }
537         if(mode!=2)    egg(num);
538         SetColor(c,0); 
539         sp("恭喜!!!",TIME*3);
540         SetColor(f,0);
541         if(array[num]) SetColor(c,0),sp(sentence[rand()%sentence.size()]),cout<<endl;
542         
543         switch(array[num]) {
544             case 1:{
545                 sp("小优秀 * 1 !
");
546                 break;
547             }
548             case 2:{
549                 sp("小优秀 * 2 !
");
550                 break;
551             } 
552             case 3:{
553                 sp("小优秀 * 3 !
");
554                 break;
555             } 
556             case 4:{
557                 sp("小优秀 * 4 !
");
558                 sp("看来你小优秀蛮多嘛。分点给大家哈!
",TIME/2);
559                 break;
560             } 
561             default:{
562                 if(num!=30)
563                     sp("奖励俗蠊最高领导人王宇翔的一个吻!!!
");
564                 else
565                     sp("自己亲自己一下?(开玩笑,别生气哈)
");
566                 sp("Sorry,没有小优秀咯……
");
567                 break;
568             }
569         }
570         if(book[num]) SetColor(f,6),cout<<"此学号已经抽过了
";
571         else tot++,stats[array[num]]++;
572         book[num]=true;
573         SetColor(f,0);
574         cout<<endl<<endl;
575     }
576     cin.get();
577     cin.get();
578     system("cls");
579     SetColor(c,0);
580     system("title GOOD LUCK");
581     sp("				over
所有的学号都抽完了!

请到save.txt中查看保存的数量

没有得到小优秀也不要灰心

不要一下子把运气用完了嘛~

总之,祝大家元旦快乐!!!aaa");
582     cin.get();
583     return 0;
584 }
585 /*
586 
587  0 = 黑色       8 = 灰色
588  1 = 蓝色       9 = 淡蓝色
589  2 = 绿色       A = 淡绿色
590  3 = 浅绿色     B = 淡浅绿色
591  4 = 红色       C = 淡红色
592  5 = 紫色       D = 淡紫色
593  6 = 黄色       E = 淡黄色
594  7 = 白色       F = 亮白色
595 
596 
597 
598 char ch=getchar();
599     int ans=0;
600     while(ch<'0'||ch>'9'&&ch!='s'&&ch!='
') 
601     {
602         ch=getchar();
603     }
604     
605     
606 switch() {
607     default:
608 }
609 
610 
611 
612 
613 
614 */
615 
616 void egg(int num)
617 {
618     if(num==30)
619     {
620         SetColor(d,1);
621         sp("恭喜本学号蠊翔哥,你这辈子都别想中小优秀了!!!!
"); 
622         Sleep(3000);
623     }
624     if(num==8)
625     {
626         SetColor(f,8);
627         sp("Coder 表示他应该绝对没有作弊……
",TIME/2);
628     }
629     if(num==5)
630     {
631         SetColor(e,0);
632         sp("腾总元旦快乐!
");
633     }
634     if(num==35)
635     {
636         SetColor(e,0);
637         sp("吉祥如意罩着,招财进宝护着,财神爷看着,各路神仙把场捧着,小优秀不发(给我们)才怪!
King!求发小优秀!!!
");
638     }
639     SetColor(f,0);//颜色还原 
640 }

Download

点我

End

原文地址:https://www.cnblogs.com/send-off-a-friend/p/12115279.html