Advertisement
a53

coduri

a53
Nov 19th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("coduri.in");
  6. ofstream g("coduri.out");
  7. int n, h, d;
  8. char a[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'},c,cod[65], cod1[65];
  9. char w[64]={'0','0','0','0','0','0','0','1','0','0','1','0','0','0','1','1','0','1','0','0','0','1','0','1','0','1','1','0','0','1','1','1','1','0','0','0','1','0','0','1','1','0','1','0','1','0','1','1','1','1','0','0','1','1','0','1','1','1','1','0','1','1','1','1'};
  10. int i,j,x,q,nrx=0,nrg;
  11. int main()
  12. {
  13. f>>n>>h>>d;
  14. for(i=1;i<=n;i++)
  15. {
  16. f>>c;
  17. if(c=='H')
  18. {
  19. for(j=1;j<=h;j++)
  20. {
  21. f>>cod[j];
  22. if(cod[j]>'9') q=cod[j]-'A'+10; else q=cod[j]-'0';
  23. g<<w[4*q+0]<<w[4*q+1]<<w[4*q+2]<<w[4*q+3];
  24. }
  25. }
  26. else
  27. if(c=='D')
  28. {
  29. for(int k=1;k<=d;k++)f>>cod1[k];
  30. for(j=1;j<=h;j++)
  31. {
  32.  
  33. x=(cod1[j*4-3]-'0')*8+(cod1[j*4-2]-'0')*4+(cod1[j*4-1]-'0')*2+(cod1[j*4]-'0');
  34. g<<a[x];
  35. }
  36. }
  37. else
  38. {
  39.  
  40. for(j=1;j<=h;j++)
  41. f>>cod[j];
  42. nrg=0;
  43. for(int k=1;k<=d;k++)f>>cod1[k];
  44. for(j=1;j<=h;j++)
  45. {
  46.  
  47. if(cod[j]=='X')
  48. {
  49. if(cod1[j*4-3]!='X'&&cod1[j*4-2]!='X'&&cod1[j*4-1]!='X'&&cod1[j*4]!='X')
  50. {
  51. x=(cod1[j*4-3]-'0')*8+(cod1[j*4-2]-'0')*4+(cod1[j*4-1]-'0')*2+(cod1[j*4]-'0');
  52. cod[j]=a[x];
  53. }
  54. else nrg++;
  55. }
  56. }
  57. if(nrg>0) {nrx++;g<<0;}
  58. else
  59. for(j=1;j<=h;j++)
  60. {
  61. g<<(char) cod[j];
  62. }
  63. }
  64.  
  65. g<<'\n';
  66.  
  67. }
  68. g<<nrx;
  69. g.close();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement