Advertisement
a53

asciimat

a53
Feb 9th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #define DIM 3001
  4. #define LCUV 100
  5. #define NCUV 300
  6. using namespace std;
  7. ifstream fin("asciimat.in");
  8. ofstream fout("asciimat.out");
  9. char s[DIM],*p; /// fiecare caracter codificat ocupa 7 elemente
  10. int m[NCUV+5][LCUV*7+5],cer,k,nr,i,j,t,x,poz,l,c,d1=1,d2=1; /// d1,d2 dimensiunile matricei m
  11. int main()
  12. {
  13. fin>>cer;
  14. fin.get();
  15. fin.getline(s,DIM);
  16. fin>>k;
  17. /// construire matrice
  18. p=strtok(s," ");
  19. while(p)
  20. {
  21. j=1;
  22. for(t=0;p[t];++t)
  23. {
  24. x=p[t];
  25. poz=0;
  26. while(x)
  27. {
  28. m[d1][j+(7-poz)]=x%2;
  29. poz++;
  30. x=x/2;
  31. }
  32. j=j+7; /// urmatorul caracter
  33. }
  34. if(j>d2)
  35. d2=j; /// d2 primea j-7
  36. p=strtok(0," ");
  37. ++d1;
  38. }
  39. ++d2; /// d2 il consider cu 1 mai mare decat numarul de coloane
  40. for(i=1;i<d1;++i)
  41. for(j=1;j<d2;++j)
  42. m[i][j]=m[i][j]+m[i-1][j]+m[i][j-1]-m[i-1][j-1];
  43. if(cer==1) /// cerinta problemei 1
  44. {
  45. k=max(d1,d2);
  46. for(;k>2;--k)
  47. for(i=1;i<=d1-k;++i)
  48. for(j=1;j<=d2-k;++j)
  49. {
  50. l=i+k-1;
  51. c=j+k-1;
  52. if(m[l][c]-m[i-1][c]-m[l][j-1]+m[i-1][j-1]==k*k)
  53. {
  54. fout<<k;
  55. return 0;
  56. }
  57. }
  58.  
  59. }
  60. if(cer==2) /// cerinta problemei 2
  61. {
  62. for(i=1;i<=d1-k;++i)
  63. for(j=1;j<=d2-k;++j)
  64. {
  65. l=i+k-1;
  66. c=j+k-1;
  67. if(m[l][c]-m[i-1][c]-m[l][j-1]+m[i-1][j-1]==k*k)
  68. ++nr;
  69. }
  70. fout<<nr;
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement