当前位置: 首页> 游戏> 单机 > 商标网商标购买_长春互联网推广_上海优化公司选哪个_环球资源网官方网站

商标网商标购买_长春互联网推广_上海优化公司选哪个_环球资源网官方网站

时间:2025/7/11 8:49:10来源:https://blog.csdn.net/qq_74047911/article/details/142222825 浏览次数:0次
商标网商标购买_长春互联网推广_上海优化公司选哪个_环球资源网官方网站

大家好,这里是国中之林!
❥前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。有兴趣的可以点点进去看看←

问题:

这里是引用
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

解答:

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <fstream>
#include <vector>using namespace std;const int NUM = 26;//const string wordlist[NUM] = { "apiary","beetle","cereal","danger","ensign","florid",
//                            "garage","health","insult","jackal","keeper","loaner",
//                            "manage","nonce","onset","plaid","quilt","remote","stolid"
//                            "train","useful","valid","whence","xenon","yearn","zippy" };int main()
{ifstream fin;fin.open("word.txt", ifstream::in);if (!fin.is_open()){cerr << "Can't open file word.txt." << endl;exit(EXIT_FAILURE);}string word;vector<string>wordlist;if (fin.good()){while (fin >> word){wordlist.push_back(word);}}int length = wordlist.size();fin.close();srand(time(0));char play;cout << "Will you play a word game? <y/n> ";cin >> play;play = tolower(play);while (play=='y'){string target = wordlist[rand() % NUM];int length = target.length();string attempt(length, '-');string badchars;int guesses = 6;cout << "Guess my secret word.It has " << length << " letters,and you guess\n" << "one letter at a time.You get " << guesses << " wrong guesses.\n";cout << "Your word: " << attempt << endl;while (guesses>0&&attempt!=target){char letter;cout << "Guess a latter: ";cin >> letter;if (badchars.find(letter) != string::npos || attempt.find(letter) != string::npos){cout << "You already guessed char.Try again.\n";continue;}int loc = target.find(letter);if (loc == string::npos){cout << "Oh, bad guess!\n";--guesses;badchars += letter;}else{cout << "Good guess!\n";attempt[loc] = letter;loc = target.find(letter, loc + 1);while (loc!=string::npos){attempt[loc] = letter;loc = target.find(letter, loc + 1);}}cout << "Your word: " << attempt << endl;if (attempt != target){if (badchars.length() > 0){cout << "Bad choices: " << badchars << endl;cout << guesses << " bad guess left\n";}}}if (guesses > 0){cout << "That's right!\n";}else{cout << "Sorry, the word is " << target << ".\n";}cout << "Will you play another?<y/n>";cin >> play;play = tolower(play);}cout << "Bye\n";return 0;
}

运行结果:
在这里插入图片描述

考查点:

  • string类
  • cctype
  • 随机数
  • ifstream读文件
  • vector容器

注意:

  • find若找到字符返回对应的位置,可以设置起始位置找,下面就是找后面有没有重复的字母.
    在这里插入图片描述

2024年9月17日11:02:45

关键字:商标网商标购买_长春互联网推广_上海优化公司选哪个_环球资源网官方网站

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: