小苹果改编问题

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,x,s_x;
	cin>>n>>x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		a[i]=i+1;
	}
	int j=0,t,d=0;
	int s=0;
	while(n){
		t=0;
		s++;
		cout<<"小苞第"<<s<<"天拿走了编号为";
		for(int i=0;i<n;i+=3){
			cout<<a[i]<<" ";
			if(a[i]==x){
				s_x=s;
			}
			a[i]=0;
			t++;
		}
		cout<<"的苹果"<<endl;
		j=0;d=0;
		for(int i=0;i<n;i++){
			if(a[i]!=0){
				b[j]=a[i];
				j++;
				a[d]=b[d];
				d++;
			}
			
		}
		n-=t;
		
	}
	cout<<endl<<"编号为"<<x<<"的苹果,在第"<<s_x<<"天被拿走!";
	return 0;
}

  

posted @ 2024-10-05 08:46  fushuxuan1  阅读(21)  评论(0编辑  收藏  举报