Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3.  
  4. using namespace std;
  5.  
  6. string binary(int n){
  7. string res="";
  8. while(n>0){
  9. res=char(n%2+'0')+res;
  10. n/=2;
  11. }
  12. while(res.length()<8){
  13. res='0'+res;
  14. }
  15. return res;
  16. }
  17.  
  18. char T[1000][1000];
  19.  
  20.  
  21.  
  22. int main(){
  23. int n,m;
  24. scanf("%d%d",&n,&m);
  25. int num;
  26. int k=0,r=0;
  27. while(scanf("%d",&num)==1){
  28. string met=binary(num);
  29. // cout<<num<<":"<<met<<endl;
  30. for(int i=0;i<met.length();i++){
  31. T[k][r]=met[i];
  32. r++;
  33. if(r==m){
  34. k++;
  35. r=0;
  36. }
  37. }
  38. }
  39. for(int i=0;i<n;i++){
  40. for(int j=0;j<m;j++){
  41. cout<<T[i][j];
  42. }
  43. cout<<endl;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement