Advertisement
mr-blood

[KeygenMe] Matrix

Mar 25th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. //~ using namespace std;
  4.  
  5. using std::cout;
  6. using std::cin;
  7. using std::getline;
  8. using std::endl;
  9. using std::string;
  10.  
  11. class Matriz
  12. {
  13.     public:
  14.        
  15.         Matriz(int a): elementos(a)
  16.         {
  17.             int i;
  18.             Elements=new int*[a];
  19.             for(i=0;i<=a;i++)
  20.                 Elements[i]=new int[a];
  21.         };
  22.        
  23.         int codifica();
  24.        
  25.         Matriz operator*(Matriz A);
  26.         void insert(int row, int col, int value);
  27.        
  28.         int elementos;
  29.         void MUL(Matriz A, Matriz B);
  30.     //~ private:
  31.         int **Elements;
  32. };
  33.  
  34. int Matriz::codifica()
  35. {
  36.     int hash=0;
  37.    
  38.     for(int i=0;i<elementos;i++)
  39.         for(int j=0;j<elementos;j++)
  40.             hash+=Elements[j][i];
  41.        
  42.     return hash;
  43. }
  44.  
  45. void Matriz::insert(int row, int col, int value)
  46. {
  47.     Elements[row][col]=value;
  48. }
  49.  
  50. Matriz Matriz::operator*(Matriz A)
  51. {
  52.     Matriz temp(A.elementos);
  53.    
  54.     temp.MUL((*this), A);
  55.    
  56.     return temp;
  57. }
  58.  
  59. void Matriz::MUL(Matriz A, Matriz B)
  60. {
  61.     int i, j, k;
  62.    
  63.     for(i=0;i<A.elementos;i++)
  64.         for(j=0;j<A.elementos;j++)
  65.             this->Elements[i][j]=0;
  66.    
  67.     for(i=0;i<=A.elementos;i++)
  68.     {
  69.         for(j=0;j<A.elementos;j++)
  70.         {
  71.             for(k=0;k<A.elementos;k++)
  72.             {
  73.                 this->Elements[i][j]+=A.Elements[i][k]*B.Elements[k][j];
  74.             }
  75.         }
  76.     }
  77. }
  78.  
  79. int main()
  80. {
  81.     Matriz A(3), B(3), C(3);
  82.    
  83.     string usuario, pass;
  84.    
  85.     cout<<"User: ";
  86.     getline(cin, usuario);
  87.     cout<<"Pass: ";
  88.     getline(cin, pass);
  89.    
  90.     if(usuario.length()!=9 or pass.length()!=9)
  91.     {
  92.         cout<<"Denegado"<<endl;
  93.         return 0;
  94.     }
  95.    
  96.     for(int i=0;i<3;i++)
  97.         for(int j=0;j<3;j++)
  98.             A.insert(i, j, usuario[3*i+j]);
  99.    
  100.     for(int i=0;i<3;i++)
  101.         for(int j=0;j<3;j++)
  102.             B.insert(i, j, pass[3*i+j]);
  103.    
  104.     C= A*B;
  105.     if(C.codifica() == 314875)
  106.         cout<<"Aceptado"<<endl;
  107.     else
  108.         cout<<"Denegado"<<endl;
  109.    
  110.     cin.get();
  111.    
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement