fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n,k=0;
  9. cin >> n;
  10. while(n--)
  11. {
  12. k++;
  13. char str[20][20],str1[441],str2[441];
  14. int r,c,count=0;
  15. cin >> r >> c;
  16. //nhap ma tran
  17. for(int i=0;i<r;i++)
  18. for(int j=0;j<c;j++)
  19. cin >> str[i][j];
  20. //xu ly ma tran xoay oc
  21. //chuyen cac ki tu dang xoay oc vao 1 xau khac
  22. int gt=0,t=0,d=r-1,e=c-1;
  23. while(gt<r*c)
  24. {
  25. for(int i=t;i<=e;i++) //duyet tu trai sang phai
  26. {
  27. str1[gt]=str[t][i];
  28. gt++;
  29. }
  30. for(int i=t+1;i<=d;i++) //tu tren xuong duoi
  31. {
  32. str1[gt]=str[i][e];
  33. gt++;
  34. }
  35. for(int i=e-1;i>=t;i--) //tu phai sang trai
  36. {
  37. str1[gt]=str[d][i];
  38. gt++;
  39. }
  40. for(int i=d-1;i>t;i--) //duoi len tren
  41. {
  42. str1[gt]=str[i][t];
  43. gt++;
  44. }
  45. t++;d--;e--; //thu nho ma tran
  46. }
  47. //xu ly chuyen 5 bit thanh so tuong ung
  48. for(int i=0;i<r*c;i++)
  49. {
  50. int f=0;
  51. int o=4;
  52. if((4+i)>r*c-1) break;
  53. for(int j=i;j<=i+4;j++)
  54. {
  55. f+=(str1[j]-'0')*pow(2,o);
  56. o--;
  57. }
  58. if(f==0) str2[count]=32; //neu f=0 thi cho thanh ki tu khoang trang
  59. else if(f>0)
  60. str2[count]=f+64;
  61. i+=4;
  62. count++;
  63. }
  64. cout << k << " ";
  65. for(int i=0;i<count;i++)
  66. cout << str2[i];
  67. cout << endl;
  68.  
  69. }
  70. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty