猴子报数

来源:互联网 发布:java 中级面试题 编辑:程序博客网 时间:2024/06/02 17:35

Description

有做组测试数据.每一组数据有两行,第一行输入n(表示猴子的总数最多为100)第二行输入数据s(从第s个猴子开始报数)和数据m(第m个猴子退出报数).当输入0 0 0时表示程序结束.

Input

输出中,每组数据的输出结果为一行,中间用逗号间隔。

Output
1
2
3
4
5
6
7
8
10
2 5
5
2 3
0
0 0
Sample Input
1
2
6,1,7,3,10,9,2,5,8,4
4,2,1,3,5
Sample Output



#include<stdio.h>int main(){    int n,s,m;    while(scanf("%d %d %d",&n,&s,&m)!=EOF)    {        int houzi[101]={0};        int pos=s,count=0,h=0;        if(n==0 && s==0 && m==0)            break;        while(h<n)        {            if(houzi[pos] == 0)            {                count++;                                 if(count == m)                {                    houzi[pos]= 1;                    count=0;                    if(h==0)                        printf("%d",pos);                    else                        printf(",%d",pos);                    h++;                }                                              }            pos++;            if(pos == n+1)                pos=1;        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击