250x250
    
    
  
                              Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        반응형
    
    
    
  | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                            Tags
                            
                        
                          
                          - math
 - Properties
 - CSS
 - spring boot
 - set
 - BFS
 - 큐
 - Java
 - union_find
 - map
 - 스프링부트
 - 리소스모니터링
 - alter
 - List
 - Union-find
 - priority_queue
 - JPA
 - GC로그수집
 - Calendar
 - NIO
 - 스택
 - scanner
 - date
 - deque
 - string
 - html
 - 힙덤프
 - javascript
 - dfs
 - sql
 
                            Archives
                            
                        
                          
                          - Today
 
- Total
 
매일 조금씩
백준 5555번: 반지 본문
728x90
    
    
  반응형
    
    
    
  


bool 을 사용하여 알파벳을 찾을때
일치하는지 확인하는 것보다 일치하지않는 철자가 나올경우 바로 false로 바꾸고 break하는 것이 더 효율적이다.
3중 for문을 사용한다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	int n;
	int cnt = 0;
	
	cin >> s;
	cin >> n;
	vector<string> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		bool ring = false;
		for (int j = 0; j < 10; j++) {
			if (v[i][j] == s[0]) {
				bool flag = true;
				for (int k = 0; k < s.length(); k++) {
					if (v[i][(j + k) % 10] != s[k]) {
						flag = false;
						break;
					 }
				}
				if (flag) {
					ring = true;
					break;
				}
			}
		}
		if (ring)
			cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}
728x90
    
    
  반응형
    
    
    
  '알고리즘' 카테고리의 다른 글
| 백준 1717번: 집합의 표현 (0) | 2020.03.08 | 
|---|---|
| 백준 5218번: 알파벳 거리 (0) | 2020.02.16 | 
| 백준 5598번: 카이사르 암호 (0) | 2020.02.12 | 
| 백준 11656번: 접미사 배열 (0) | 2020.02.11 | 
| 백준 2897번: 몬스터 트럭 (0) | 2020.02.09 |