/*This is a test*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
struct ren
{
int id,times;
};
typedef struct ren R;
int main()
{
int n, x, y, z, k = 1, cishu = 1, he=0;
printf("几个人?玩几次?\n");
scanf("%d %d", &n,&z);
R ren[99];
if (n < 5 || n>20||z<10||z>30)
{
printf("error:5<=n<=20,10<=z<=30"); return -1;
}
for (int i = 1; i <= n; i++)
{
ren[i].id = i; ren[i].times = 0;
}
srand(time(NULL));
while (cishu <= z)
{
x= rand() % 4 + 2;
if (k + x <= n)
k += x;
else
k = k + x - n;
y = rand()%3+ 1;
ren[k].times += y;
he+=y;
cishu++;
}
printf("喝过酒的人及其喝过的杯数为:\n");
for (int i = 1; i <= n; i++)
{
if (ren[i].times != 0)printf("[%d]号:%d杯\n",i,ren[i].times);
}
printf("小明需要付款%f元",5*ceil(he/3));
}
C-喝酒传花
最新推荐文章于 2024-10-02 14:37:57 发布