- #include<bits/stdc++.h>
- using namespace std;
- float b=0;
- int a;
- int cab(int r)
- {
- if(r==0)
- {
- b++;
- }
- return b;
- }
- void pr(int r)
- {
- if(r==1)
- {
- cout<<"front";
- }
- else
- {
- cout<<"back";
- }
- }
- void ed()
- {
- cout<<"\n\nfront: "<<a-b<<"\tback: "<<b<<"\nThe proportion of the front is: "<<(a-b)/a*100<<"%\nthe proportion of the back is: "<<b/a*100<<"%";
- }
- int main()
- {
- cout<<":";
- cin>>a;
- srand(time(NULL));
- int r=0;
- for(int i=0;i<a;i++)
- {
- r=rand()%2;
- pr(r);
- cab(r);
- cout<<"\n";
- }
- ed();
- return 0;
- }
複製代碼 |