2018年第九届蓝桥杯【C++省赛B组】【第二题:明码】

时间:2022-04-27 18:53:19

参考:https://blog.csdn.net/qq_34202873/article/details/79784242

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,m;
 6     freopen("in.txt","r",stdin);
 7     while (cin>>n>>m)
 8     {
 9         bitset<8> b(n);
10 //        string s=b.to_string();
11         bitset<8> c(m);
12 //        string sb=c.to_string();
13 //        cout<<s<<sb<<endl;
14         for (int i=7;i>=0;i--)//注意下标是从左到右递减,最右的位是0!!
15         {
16             if (b.test(i))
17             {
18                 cout<<"*";
19             }
20             else
21             {
22                 cout<<" ";
23             }
24         }
25         for (int i=7;i>=0;i--)
26         {
27             if (c.test(i))
28             {
29                 cout<<"*";
30             }
31             else
32             {
33                 cout<<" ";
34             }
35         }
36         cout<<endl;
37     }
38 
39     return 0;
40 }