CSP小苹果详细解法
#include <iostream> using namespace std; int main(){ int n,x; cin>>n>>x; cout<<"小苞的桌上一共放了"<<n<<"个苹果。"<<endl; int a[n+5]; for(int i = 1;i<=n;i++){ a[i] = i; } int ant = 0,t,j,j1; while(n){ t = 0; ant++; cout<<"小苞第"<<ant<<"天拿走了编号为"; for(int i = 1;i<=n;i+=3){ if(a[i]==x){ j1 = ant; } cout<<a[i]<<"、"; a[i] = 0; t++; } cout<<"\b\b的苹果。"<<endl; j = 1; for(int i = 1;i<=n;i++){ if(a[i]!=0){ a[j] = a[i]; j++; } } n -= t; } cout<<"编号为"<<x<<"的苹果是在第"<<j1<<"天拿走的。"; return 0; }