怎么还是实现不了我要实现的
avr 2005-10-02 06:56:56 高手们帮帮忙啊。
我的这段程序是想实现以下功能的,输入1个整数。在1—1600中:
1.1-1600随机生成一个数,当这个随机数与当前数count一致时输出950,即我的printA()。
2.1-400中随机生成一个数,401-800中随机生成一个数,801-1200随机生成一个数,1201-1600随机生成2个数。当这些随机数与当前数count一致时输出850,即我的printB()。
3.1-100中随机生成一个数,101-200中随机生成一个数,201-300中随机生成一个数,301-400中随机生成一个数,后面的401-1600每100都按顺序重复这些操作。当这些随机数与当前数count一致时输出750,即我的printC()。
4.1-100中随机生成2个数,101-200中随机生成3个数,后面的301-1600每100都按顺序重复这些操作。当这些随机数与当前数count一致时输出650,即我的printD()。
5.其余的都输出250,即我的printH()。
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int count=1 ;
bool printA(int a)
{int k,a=1600;
k=rand()%a;
if(count==k)
{ cout<<"950"<<endl;
count++;
return true;
}
return false;
}
bool printB(int b)
{int k,m,n,b=400,step=0;
for(m=0;m<3;m++)
{k=rand()%b+step;
if(count==k){
cout<<"850"<<endl;
count++;
step+=400;
}
while(step==1200){
for(n=0;n<2;n++)
{k=rand()%b+step;
if(count==k){
cout<<"850"<<endl;
count++;}
}
return true;
}
return false;
}
bool printC(int c)
{int k,m,n,l,c=100,step=0;
for(m=0;m<12;m++)
{k=rand()%c+step;
if(count==k){
cout<<"750"<<endl;
count++;
step+=100;
}
while(step==300||step==700||step==1100)
{for(n=0;n<2;n++){
k=rand()%c+step;
if(count==k)
{cout<<"750"<<endl;
count++;}
}
}
step+=100;
while(step==1500)
{for(l=0;l<2;l++){
k=rand()%c+step;
if(count==k){
cout<<"750"<<endl;
count++;}
}
}
return true;
}
return false;
}
bool printD(int d)
{int k,m,n,l,d=100,step=0;
for(l=0;l<8;l++){
for(m=0;m<2;m++)
{k=rand()%d+step;
if(count==k){
cout<<"650"<<endl;
count++;}
}
step+=100;
for(n=0;n<3;n++)
{k=rand()%d+step;
if(count==k){
cout<<"650"<<endl;
count++;}
step+=100;
}
return true;
}
return false;
}
bool printH(int h)
{cout<<"250"<<endl;
count++;
return true;
}
int main()
{int n,x,y,w;
cin<<n<<endl;
(int) x=n/1600;
for(w=0;w<x;w++){
srand((unsigned)time(NULL));
for(y=1600;y>0;y--)
{if(printA(a)) continue;
if(printB(b)) continue;
if(printC(c)) continue;
if(printD(d)) continue;
printH(h);
}
return 0;
}
}