猜单词
来源:互联网 发布:mysql查询重复的记录 编辑:程序博客网 时间:2024/05/16 00:33
#include <iostream> #include <string> #include <ctime> #include <cstdlib> using namespace std; //用于打乱单词的函数 string mixLetters(string word) { string mixedWord; int position(0); //只要还没有抽完单词里的所有字母,就继续while循环 while (word.size() != 0) { //在单词中随机选择一个字母 position = rand() % word.size(); //将此字母添加到新的单词mixedWord中,也就是我们最后得到的打乱的单词 mixedWord += word[position]; //将此字母从字符串中删去 //为了不重复处理同一个字母 word.erase(position, 1); } //返回打乱后的单词 return mixedWord; } int main() { string secretWord, mixedWord, userEnteredWord; //初始化伪随机数的种子 srand(time(0)); //1 : 请求玩家1输入原始单词 cout << "输入一个单词" << endl; cin >> secretWord; //2 : 用函数mixLetters将玩家1输入的原始单词打乱顺序 mixedWord = mixLetters(secretWord); //3 : 请求玩家2猜单词 do { cout << endl << "原先的单词是什么 ? " << mixedWord << endl; cin >> userEnteredWord; if (userEnteredWord == secretWord) { cout << "猜对了! 好棒!" << endl; } else { cout << "猜错了!" << endl; } } while (userEnteredWord != secretWord);//只要没猜对,就再进入while循环 return 0; }
0 0
- 猜单词
- 猜单词
- 1391 猜单词啦
- 猜单词游戏
- 模拟猜单词游戏
- 【c++】猜单词游戏
- 猜单词的游戏
- Python小游戏 -- 猜单词
- 猜单词游戏
- 单词。。
- 单词
- 单词
- 单词
- 单词:
- 单词
- 单词
- 单词
- 单词
- UVALive 7427Elementary Math
- (17)while do while 语句 (18)for循环语句 (19)break contiue
- jenkins安装(已下载部分插件版
- 超详细 Servlet工作原理解析
- Centos 安装Sublime text 3
- 猜单词
- 设置双卡不同的来电默认铃声
- 图结构练习——判断给定图是否存在合法拓扑序列
- java中的那些坑(一)
- java一道多线程题,子线程循环10次,主线程接着循环100次,如此循环50次的问题
- js格式化日期
- 湖南省大学生计算机程序设计竞赛(残缺的棋盘)
- db2-event monitor
- 虚拟机sandbox启动不起来的原因