Advertisement
juneba

Untitled

Jul 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.     int qtd;
  9.     string linha;
  10.     char res[1000];
  11.     int tamanho;
  12.     int diamantes =0;
  13.  
  14.  
  15.     cin >> qtd;
  16.  
  17.  
  18.  
  19.     for (int i = 0 ; i < qtd; i++)
  20.     {
  21.         diamantes = 0;
  22.         cin >> linha;
  23.         int k = 0 ;
  24.         for (int j = 0 ; j < linha.size() ; j++)
  25.         {
  26.  
  27.             if ( linha[j] != '.')
  28.             {
  29.                 res[k] = linha[j];
  30.                 k++;
  31.             }
  32.             res[k] = '\0';
  33.  
  34.  
  35.             tamanho = k;
  36.  
  37.         }
  38.  
  39.         int continua =1;
  40.         while  (continua)
  41.         {
  42.             continua = 0;
  43.             int esquerda =0 ;
  44.             for ( int i = 0 ; i < tamanho ; i++)
  45.             {
  46.                 if (res[i] == '<')
  47.                 {
  48.                     esquerda = i;
  49.                 }
  50.                 else {
  51.                     if (res[esquerda] == '<' && res[i] == '>')
  52.                     {
  53.                         diamantes++;
  54.                         res[esquerda] = 'x';
  55.                         //printf("%c", res[esquerda]); // não sobreescreve?
  56.                         res[i] = 'x';
  57.                         continua = 1;
  58.                         //cout << "entrou" <<endl;
  59.                     }
  60.  
  61.                 }
  62.  
  63.                 //cout << " parcial =>  " << res << endl;
  64.  
  65.             }
  66.  
  67.  
  68.         }
  69.         printf("%d",diamantes);
  70.         //printf("Diamantes : %d" , diamantes);
  71.         //cout <<  tamanho << endl;
  72.         //cout << res;
  73.  
  74.     }
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement