```
int countBattleships(vector<vector<char>>& board) {
if(!board.size()) return 0;
int count=0;
int n=board.size(),m=board[0].size();
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(board[i][j]=='X'){
if(i>0 && board[i-1][j]=='X') continue;
count++;
while(j<m && board[i][j]=='X') j++;
}
return count;
}
```