猜商品价格游戏
#include<iostream>
using namespace std;
int main()
{
int price;//输入商品的真实价格
cin>>price;
int p=0; //初始化商品的试猜价格
int count=0;
while(price!=p)
{
cin>>p;//输入商品的试猜价格
if(p<price)
{
cout<<"猜的过低"<<endl;
}
else if(p>price)
{
cout<<"猜的过高"<<endl;
}
else{
cout<<"猜对了"<<endl;
}
count++;
}
cout<<"一共猜了"<<count<<"次"<<endl;
return 0;
}
枚举法完成填数游戏
#include<iostream>
using namespace std;
int main()
{
long long mul,result;
for(int i1=1;i1<=9;i1++)
{
for(int i2=0;i2<=9;i2++)
{
for(int i3=0;i3<=9;i3++)
{
for(int i4=0;i4<=9;i4++)
{
for(int i5=1;i5<=9;i5++)
{
mul=i1*10000+i2*1000+i3*100+i4*10+i5;
result=i5*100000+i5*10000+i5*1000+i5*100+i5*10+i5;
if(mul*i1==result)
{
printf("\n%5d%2d%2d%2d%2d\n",i1,i2,i3,i4,i5);
printf("x%12d\n",i1);
printf("________________\n");
printf("%3d%2d%2d%2d%2d%2d\n",i5,i5,i5,i5,i5,i5);
}
}
}
}
}
}
return 0;
}
填运算符