社区讨论
这个代码我能玩一下午
灌水区参与者 6已保存回复 9
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 9 条
- 当前快照
- 1 份
- 快照标识符
- @m5hleb3j
- 此快照首次捕获于
- 2025/01/04 10:56 去年
- 此快照最后确认于
- 2025/11/04 12:00 4 个月前
CPP
#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;
}
猜数游戏智能版
手动版
CPP#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;
}
回复
共 9 条回复,欢迎继续交流。
正在加载回复...