Top coder competition May 26th,2007

来源:互联网 发布:mysql 5.7.20.tar.gz 编辑:程序博客网 时间:2024/05/17 16:46

My code as below for the first item: 

#include "stdafx.h"
#include "vector"
#include "string"
using namespace std;

class FirstMazeTask
{
public:
 string checkCorrectness(vector <string> maze)
 {
  bool b_overlap = false;
  bool b_visited[26] = {false};
  string str_RetVal("Everything is ok!");
  int count = maze.size();
  int n_DotCount = 0;


  for(int i=0; i<count; i++)
  {
   string str_temp = maze[i];
   int n_size_str_temp = str_temp.size();
   for (int j=0; j<n_size_str_temp; j++)
   {
    if(str_temp[j] == '.') ++n_DotCount;
    else if( str_temp[j]>='A' &&str_temp[j]<='Z')
    {
     if(b_visited[str_temp[j] - 'A' +1])
     {
      b_overlap = true;
     }
     else
     {
      b_visited[str_temp[j] - 'A' +1] = true;
     }

    }
   }
  }

  if(n_DotCount<3)
  {
   str_RetVal = "There are less than 3 empty cells!";
   return str_RetVal;
  }

  if(b_overlap)
  {
   str_RetVal = "There are at least two equal letters!";
   return str_RetVal;   
  }

  return str_RetVal;

 }

};

 


int main(int argc, char* argv[])
{
 vector <string> vs;
 string s1("A.B");
 vs.push_back(s1);
  s1= "....." ;
 vs.push_back(s1);
 s1 = "B....";
 vs.push_back(s1);
 FirstMazeTask fm;
 string srt = fm.checkCorrectness(vs);

//{"A..",
// "#.#",
// "#.B"}
 // printf("Hello World!/n");
 return 0;
}

原创粉丝点击