#include<bits/stdc++.h>
#include<cstdio>
#include<windows.h>
#pragma comment (lib, "User32.lib")
using namespace std;
int n_cs(int n)
{
int t=0,s=1;
while (s<n)
{
s*=2;
t++;
}
return t;
}
int main()
{
srand(time(0));
int chlen=rand()%50000;
char ch[chlen];
//string str[]={"你干嘛~哈哈哎呦","哈嗨嗨,我又来-当老六","针不戳,住在山里面-针不戳"};
for (int i=0; i<=chlen; i++)
{
ch[i]=rand()%128;
}
printf("猜数字(输入0-n的数(输入n),不小于100):");
int n;
scanf("%d",&n);
while (n<100)
{
printf("错误,请重新输入:");
scanf("%d",&n);
}
int cishu=n_cs(n);
printf("你有%d次机会来猜这个数。\n",cishu);
int m=rand()%n;
int s;
for (int i=1; i<=cishu; i++)
{
printf("请输入猜的数:");
scanf("%d",&s);
if (s>m)
{
cout<<"比这个小"<<endl;
}
else if (
C++整蛊代码(猜数字)
于 2024-02-01 10:31:32 首次发布