Problem Solving
BOJ 9933 - 민균이의 비밀번호
Vjerksen
2016. 11. 21. 17:29
문제 링크
https://www.acmicpc.net/problem/9933
문제 해결
1. map을 적절히 사용하는 문제.
2. 입력 받은 문자열을 map에 저장한다.
3. 입력 받은 문자열의 역 문자열이 map에 있는 지 확인한다.
4. 만약 존재한다면 그 문자열의 길이와 가운에 글자를 출력한다.
주의할 점
1. map 구현을 잘 해야한다.
소스 보기 소스 안 보기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*
explanation in vjerksen.tistory.com
*/
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<cmath>
#include<climits>
#include<map>
#include<set>
using namespace std;
int N;
// caution 1-1 map 선언
map<string, bool> check;
string ans;
int main(){
cin >> N;
for(int i=0;i<N;i++){
string temp ="";
cin >> temp;
check[temp] = true;
reverse(temp.begin(),temp.end());
// caution 1-2 map에 이미 temp라는 원소가 있는 지 확인
if(check.count(temp)!=0){
reverse(temp.begin(),temp.end());
ans += temp;
}
}
printf("%d %c",ans.size(),ans[ans.size()/2]);
return 0;
}
소스 안 보기
※ 정확하고 부드러운 태클은 언제나 환영입니다.