https://www.acmicpc.net/problem/1652
#include<iostream>
#include<string>
using namespace std;
int main() {
int n;
int cnta = 0;
int cntb = 0;
int dot = 0;
string arr[100];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
//가로 카운트 시작
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][j] =='.' ) { // . 을 만날때마다 dot+=1
dot += 1;
}
else { // x 를 만났을때 dot가 2이상이면 cnt++ 그런다음 dot초기화
if (dot >= 2){
cnta += 1;
}
dot = 0;
}
}
if (dot >= 2) { //다음줄로 넘어갈 때는 x를 만나지 않기때문에
cnta += 1; //x를 만나지 않더라도 dot개수가 2 이상이면 cnt++
}
dot = 0;
}
dot = 0;
//세로 카운트 시작 전에 dot초기화!
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[j][i] == '.') {
dot += 1;
}
else {
if (dot >= 2) {
cntb += 1;
}
dot = 0;
}
}
if (dot >= 2) {
cntb += 1;
}
dot = 0;
}
cout << cnta << ' ' << cntb;
}
'자기개발👨💻 > 코딩 알고리즘' 카테고리의 다른 글
[python] 백준 2588 곱셈 (0) | 2020.08.29 |
---|---|
[python] 백준 1789 블랙잭 (0) | 2020.08.29 |
[python] 백준 2607 로마 숫자 (실패70 성공 20 ?? 10) (0) | 2020.08.27 |
[python] 백준 6603 로또 (0) | 2020.08.12 |
[c++] 백준 2669 직사각형 네개의 합집합의 면적 구하기 (0) | 2020.08.11 |
[c++] 백준 1912 연속합 (0) | 2020.08.11 |