https://www.acmicpc.net/problem/8958
#include <iostream>
#include <string>
using namespace std;
int main(void){
int t;
cin >> t;
while(t--){
string str;
cin >> str;
int count = 0;
int sum = 0;
for(int i = 0;i<str.size();i++){
if(str[i] == 'X'){
count = 0;
}
else{
count++;
sum = sum + count;
}
}
cout << sum << '\n';
}
}
https://www.acmicpc.net/problem/1987
#include <iostream>
using namespace std;
int max(int a,int b){
if(a>b){
return a;
}
else{
return b;
}
}
bool visited[27];
char arr[21][21];
int cnt;
int ans = 0;
int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
int r,c;
void dfs(int x,int y,int depth){
cnt = max(depth,cnt);
for(int i = 0;i<4;i++){
int nx = x + dx[i];
int ny = y + dy[i];
if((nx>=0 && nx<r) && (ny>=0 && ny<c)){
if(visited[arr[nx][ny] - 'A'] == false){
visited[arr[nx][ny] - 'A'] = true;
dfs(nx,ny,depth+1);
visited[arr[nx][ny] - 'A'] = false;
}
}
}
}
int main(void){
cin >> r >> c;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
cin >> arr[i][j];
}
}
char c = arr[0][0];
visited[c-'A'] = true;
dfs(0,0,1);
cout << cnt;
}
'알고리즘' 카테고리의 다른 글
백준 2502 떡 먹는 호랑이 C++ (0) | 2022.05.25 |
---|---|
백준 11508 C++ (0) | 2022.05.25 |
백준 9324 진짜 메시지 C++ (0) | 2022.05.18 |
2022-05-18 알고리즘 문제(백준 2096 내려가기) (0) | 2022.05.18 |
2022-05-17 알고리즘 문제 (0) | 2022.05.17 |