Advertisement
Guest User

Prova-3.e

a guest
Nov 13th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. int abs(int n)
  4. {
  5.     if(n<0)
  6.     {
  7.         return -n;
  8.     }
  9.     return n;
  10.  
  11. }
  12.  
  13. void conta_estrela(std::vector<char> &v,int posicao, int t_linha, int *r)
  14. {
  15.     if((posicao >= 0 || posicao <= v.size()) && v[posicao]=='*')
  16.     {
  17.         //std::cout << "posicao:"<<posicao << std::endl;
  18.         *r+=1;
  19.  
  20.  
  21.         v[posicao] = '.';
  22.  
  23.  
  24.         for (int i = 0; i < 3; ++i)
  25.         {
  26.             if(abs(posicao/t_linha - (posicao - t_linha +1 -i)/t_linha) ==1)
  27.             {
  28.                 conta_estrela(v,posicao - t_linha +1 -i,t_linha,r);
  29.                 //std::cout<<1<<std::endl;
  30.             }
  31.  
  32.         }
  33.  
  34.         for (int i = 0; i < 3; ++i)
  35.         {
  36.             if(abs(posicao/t_linha - (posicao + t_linha -1 +i)/t_linha)==1)
  37.             {
  38.                 conta_estrela(v,posicao + t_linha -1 +i,t_linha,r);
  39.                 //std::cout<<2<<std::endl;
  40.             }
  41.  
  42.         }
  43.  
  44.         conta_estrela(v,posicao + t_linha,t_linha,r);
  45.         conta_estrela(v,posicao - t_linha,t_linha,r);
  46.  
  47.         if(posicao/t_linha == (posicao+1)/t_linha)
  48.         {
  49.             conta_estrela(v,posicao +1,t_linha,r);
  50.             //std::cout<<3<<std::endl;
  51.         }
  52.  
  53.         if(posicao/t_linha == (posicao-1)/t_linha)
  54.         {
  55.             conta_estrela(v,posicao -1,t_linha,r);
  56.             //std::cout<<4<<std::endl;
  57.         }
  58.  
  59.     }
  60.  
  61. }
  62.  
  63.  
  64. int main()
  65. {
  66.     int x,y,resposta =0;
  67.     int rec;
  68.     std::vector<char> v;
  69.  
  70.     std::cin >> y >>x;
  71.  
  72.     for (int i = 0; i < x*y; ++i)
  73.     {
  74.         char temp;
  75.         std::cin >> temp;
  76.         v.push_back(temp);
  77.     }
  78.  
  79.     for (int i = 0; i < x; ++i)
  80.     {
  81.         for (int j = 0; j < y; ++j)
  82.         {
  83.             if(v[i+(j*x)] == '*')
  84.             {
  85.                 rec =0;
  86.                 conta_estrela(v,i+(j*x),x,&rec);
  87.                 if(rec<=1)
  88.                 {
  89.                     resposta++;
  90.                 }
  91.                 //std::cout << std::endl;
  92.                 //std::cout <<"p: " <<i+(j*x) << std::endl;
  93.                 //std::cout << "resposta: " << resposta <<" rec:"  <<rec<<std::endl;
  94.  
  95.             }
  96.         }
  97.     }
  98.     std::cout << resposta;
  99.  
  100.  
  101.  
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement