这个代码我能玩一下午
  • 板块灌水区
  • 楼主yhl123456666
  • 当前回复8
  • 已保存回复8
  • 发布时间2025/1/4 10:55
  • 上次更新2025/1/4 15:35:13
查看原帖
这个代码我能玩一下午
1345014
yhl123456666楼主2025/1/4 10:55
#include<bits/stdc++.h>
using namespace std;
int n,r=10000,l=0;
int main(){
	srand(time(0));//随机的种子
	int ans=rand()*1019%10001;
	while(1){
		 int mid=l+(r-l)/2; 
		if(mid<ans){
			cout<<mid<<" 小"<<endl;
			l=mid+1;
		}
		else if(mid>ans){
			cout<<mid<<" 大"<<endl;
			r=mid;
		}
		else{
			cout<<mid<<" 猜对了"<<endl;
			break;
		}
	}
	return 0;
}

猜数游戏智能版

手动版

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	srand(time(0));//随机的种子
	int ans=rand()*1019%10001;
	while(1){
		cin>>n;
		if(n<ans) cout<<"小"<<endl;
		else if(n>ans) cout<<"大"<<endl;
		else{
			cout<<"猜对了"<<endl;
			break;
		}
	}
	return 0;
}
2025/1/4 10:55
加载中...