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