Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   int T,length;
  10.   string s;
  11.   int counter = 0;
  12.   cin >> T;
  13.   cin.ignore(1,'\n');
  14.  
  15.   while(T--)
  16.   {
  17.     bool scarescrow[100] = {false};
  18.     int field = 0;
  19.     counter++;
  20.     cin >> length;
  21.     cin.ignore(1, '\n');
  22.     getline(cin, s);
  23.     for (int i = 0; i < length; ++i)
  24.     {
  25.       if(i == 0)
  26.       {
  27.         if(s[0] == '.')
  28.           scarescrow[0] = true;
  29.       }
  30.       else if(i == 1)
  31.       {
  32.         if(s[0] == '.')
  33.         {
  34.           scarescrow[0] = false;
  35.           scarescrow[1] = true;
  36.         }
  37.         else if(s[0] == '#' && s[1] == '.')
  38.           scarescrow[1] = true;  
  39.       }
  40.       else
  41.       {
  42.         if(scarescrow[i-1] == true)
  43.         {
  44.           if(scarescrow[i-2] == true)
  45.           {
  46.             scarescrow[i-1] = false;
  47.             scarescrow[i] = true;
  48.           }
  49.         }
  50.         else
  51.         {
  52.           if(s[i] == '.')
  53.             scarescrow[i] = true;
  54.         }
  55.       }      
  56.     }
  57.  
  58.     for (int i = 0; i < length; ++i)
  59.     {
  60.       if(scarescrow[i] == true)
  61.         field++;
  62.     }      
  63.  
  64.     cout << "Case " << counter << ": " << field << endl;
  65.  
  66.   }
  67.  
  68.   return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement