AlenAntonelli

Trazas_de_cobre_Alen

May 12th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. ///Trello, Facil, Trazas de cobre
  2. #include <iostream> /// AlenAntonelli
  3. #include <stack>
  4. using namespace std;
  5. int conecta(char cadena[ ], int pares[ ] )
  6. {
  7.     int nc=0;
  8.  
  9.     stack <int> C;
  10.     stack <int> L;
  11.     for (int i=0; cadena[i]=='L' || cadena[i]=='C'; i++)
  12.     {
  13.         if (cadena[i]=='L')
  14.             L.push(i+1);
  15.         if (cadena[i]=='C')
  16.             C.push(i+1);
  17.         if(L.size()>0 && C.size()>0)
  18.         {
  19.             nc++;
  20.             pares[(nc-1)*2]=C.top();
  21.             pares[(nc-1)*2+1]=L.top();
  22.             C.pop();
  23.             L.pop();
  24.         }
  25.     }
  26.     return nc;
  27. }
  28.  
  29. int main ()
  30. {
  31.     string aux;
  32.     cin>>aux;
  33.     char cadena[aux.size()];
  34.     for (int i=0; i<aux.size(); i++)
  35.         cadena[i]=aux[i];
  36.     int pares[2000];
  37.     int nc = conecta(cadena, pares);
  38.     cout<<nc<<endl;
  39.     for (int i=0; i<nc*2; i+=2)
  40.     {
  41.         cout<<pares[i]<<" ";
  42.         cout<<pares[i+1]<<endl;
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment