2018 第九屆藍橋杯省賽總結 + 解題報告(C語言B組)2.明碼

#include <bits/stdc++.h>
using namespace std;
string foo(int n);
int main()
{
	#ifdef ONLINE_JUDGE
	#else
	freopen("in.txt", "r", stdin);
	#endif
	
	int a[10][32];
	int i, j;
	for(i = 0; i < 10; i++){
		for(j = 0; j < 32; j++){
			cin >> a[i][j];
		}
	}
	
	for(i = 0; i < 10; i++){
		for(j = 0; j < 32; j++){
			cout << foo(a[i][j]);
			
			if(j % 2 == 1) cout << endl; 
		}
	}
	
} 

string foo(int n)
{
	string str;
	int i;
	
	for(i = 0; i < 8; i++){
		if (n % 2 == 1) str += "#";
		else str += " ";
		n /= 2;
	}
	reverse(str.begin(), str.end());
	
	
	return str;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章