Advertisement
a53

trifid_EU

a53
Jan 5th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int c;
  7. ifstream f("trifid.in");
  8. f>>c;
  9. char COD[4][10];
  10. for(int i=0;i<3;++i)
  11. f>>COD[i];
  12. char s[10001];
  13. f>>s;
  14. int n=0;
  15. while(s[n]!='\0') /// Calculez lungimea n a sirului s
  16. ++n;
  17. int CL[124]; /// Codul corespunzator literei
  18. char L[334]; /// Litera corespunzatoare codului
  19. for(int i=0;i<3;++i)
  20. for(int j=0;j<9;++j)
  21. {
  22. L[(j/3+1)*100+10*(j+4-3*(j/3+1))+(i+1)]=COD[i][j];
  23. CL[(int)COD[i][j]]=(j/3+1)*100+10*(j+4-3*(j/3+1))+(i+1);
  24. }
  25. ofstream g("trifid.out");
  26. if(c==1)
  27. {
  28. int CN[30000]; /// CN este codul citit pe linii
  29. for(int i=0;i<n;++i)
  30. CN[i]=CL[(int)s[i]]/100,CN[i+n]=CL[(int)s[i]]%100/10,CN[i+n*2]=CL[(int)s[i]]%10;
  31. for(int i=0;i<n*3;i+=3)
  32. g<<L[CN[i]*100+CN[i+1]*10+CN[i+2]];
  33. }
  34. else /// c=2
  35. {
  36. int CN[30000]; /// CN este codul citit pe coloane
  37. for(int i=0,j=0;i<n*3;i+=3,++j)
  38. CN[i]=CL[(int)s[j]]/100,CN[i+1]=CL[(int)s[j]]%100/10,CN[i+2]=CL[(int)s[j]]%10;
  39. for(int i=0;i<n;++i)
  40. g<<L[CN[i]*100+CN[i+n]*10+CN[i+n*2]];
  41. }
  42. f.close(),g.close();
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement