很久很久之前做过的一道题

直接上程序,看程序说话

 1 #include<iostream>
 2 using namespace std;
 3 const int maxn=101;
 4 bool a[maxn];//a数组负责存储硬币的状态
 5 int n;//n枚硬币
 6 int main(){
 7     cin>>n;
 8     cout<<n<<endl;//因为相当于只翻一枚,所以翻n次即可
 9     for(int i=1;i<=n;i++){//i表示这是第几次翻
10         for(int j=1;j<=n;j++)//表示当前翻得是第几枚硬币
11             if(j!=i){//如果不为第i枚
12                 if(a[j])a[j]=0;//1变成0
13                 else a[j]=1;//0变成1
14             }
15             cout<<a[j];//输出当前状态
16         }
17         cout<<endl;//别忘了换行
18     return 0;
19 }

洛谷上的原版

相关文章:

  • 2022-12-23
  • 2022-02-28
  • 2021-10-10
  • 2022-03-03
  • 2021-07-22
  • 2021-11-29
  • 2021-12-12
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2018-07-10
相关资源
相似解决方案