问题标题: 酷町堂:4000

0
0
已解决
吕梓瑜
吕梓瑜
初级天翼
初级天翼

请问一下,为什么这个代码样例输出后第一个数是0?

#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
bool a[55];
int b[55];
int n,m,s,cnt,x;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	s=n;
    int pos=1;
	while(s>1){
		if(!a[pos]){
			cnt++;
			if(cnt==m){
				a[pos]=1;
                b[pos]=++x;
				cnt=0;
				s--;
			}
		}
		pos++;
		if(pos==n+1) pos=1;
	}
	for(int i=1;i<=n;i++){
		cout<<b[i]<<" ";
	}
	//fclose(stdin);
	//fclose(stdout);
    return 0;
}

能不能恳请各位大佬指出哪一行怎么改呢?或者看不懂我的代码的可以发出自己的伪代码(不要核心)

吕梓瑜在2021-10-31 12:53:38追加了内容

@李显晨  @李牧晓  @张欣悦 @张欣悦 @张欣悦1 

 

 

 

 

 


0
已采纳
李显晨
李显晨
中级启示者
中级启示者
全局:
int n,m,res,coun,cnt,pos=1;
int a[55];
主函数:
    输入n,m;
    res=n;
    while(1){
        如果(res==0) break;
        如果(!a[pos]){
            cnt++;
            如果(cnt==m){
                cnt=0;
                a[pos]=++coun;
                res--;
            }
        }
        pos++;
        如果(pos==n+1) pos=1;
    }
    循环1~n cout<<a[i]<<" ";

 

0
潘艺博
潘艺博
初级天翼
初级天翼

啊,我直接笑si

我本来打算恶搞

就写成

for(int i=1;i<=n;i++){
    if(b[i]==0) b[i]=n;
    cout<<b[i]<<" ";
 }

结果呢

AC了

我晕

我要回答