问题 K: 【字符串】密室寻宝

时间限制: 1 Sec  内存限制: 64 MB
 1 #include <iostream>
 2 #include<string>
 3 using namespace std;
 4 int p,q,a[100],b[100],c[100];
 5 int main()
 6 {
 7     cin>>p>>q;
 8     int cnt1=0,cnt2=0;
 9     while(p!=0)
10     {
11         a[cnt1++]=p%2;
12         p/=2;
13     }
14     while(q!=0)
15     {
16         b[cnt2++]=q%2;
17         q/=2;
18     }
19     int cnt=0,ans[100];
20     for(int i=0;i<8;i++)
21     {
22         c[i]=a[i]&b[i];
23         if(c[i]==1){
24             ans[cnt++]=i+1;
25         }
26     }
27     if(cnt<2)
28     {
29         cout<<"0"<<endl;
30         cout<<"Close"<<endl;
31     }
32     else
33     {
34         for(int i=0;i<cnt;i++)
35         {
36             if(i)   cout<<" ";
37             cout<<ans[i];
38         }
39         cout<<endl;
40         cout<<"Open"<<endl;
41     }
42 //    cout << "Hello world!" << endl;
43     return 0;
44 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-01-07
  • 2022-01-07
猜你喜欢
  • 2022-02-10
  • 2021-12-01
  • 2022-12-23
  • 2021-06-12
相关资源
相似解决方案