Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int main()
- {
- int c;
- ifstream f("trifid.in");
- f>>c;
- char COD[4][10];
- for(int i=0;i<3;++i)
- f>>COD[i];
- char s[10001];
- f>>s;
- int n=0;
- while(s[n]!='\0') /// Calculez lungimea n a sirului s
- ++n;
- int CL[124]; /// Codul corespunzator literei
- char L[334]; /// Litera corespunzatoare codului
- for(int i=0;i<3;++i)
- for(int j=0;j<9;++j)
- {
- L[(j/3+1)*100+10*(j+4-3*(j/3+1))+(i+1)]=COD[i][j];
- CL[(int)COD[i][j]]=(j/3+1)*100+10*(j+4-3*(j/3+1))+(i+1);
- }
- ofstream g("trifid.out");
- if(c==1)
- {
- int CN[30000]; /// CN este codul citit pe linii
- for(int i=0;i<n;++i)
- 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;
- for(int i=0;i<n*3;i+=3)
- g<<L[CN[i]*100+CN[i+1]*10+CN[i+2]];
- }
- else /// c=2
- {
- int CN[30000]; /// CN este codul citit pe coloane
- for(int i=0,j=0;i<n*3;i+=3,++j)
- CN[i]=CL[(int)s[j]]/100,CN[i+1]=CL[(int)s[j]]%100/10,CN[i+2]=CL[(int)s[j]]%10;
- for(int i=0;i<n;++i)
- g<<L[CN[i]*100+CN[i+n]*10+CN[i+n*2]];
- }
- f.close(),g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement