코딩/BOJ & 알고스팟
[BOJ 5555] 반지
hoon222y
2017. 10. 21. 15:39
https://www.acmicpc.net/problem/5555
단순하게 문자열 내에 원하는 문자열이 존재하는지에 대해 판별하는 문제이다. 이 문제를 포스팅하는 이유는 string.find() 정리하기 위함이다.
어떠한 문자열 내에서 원하는 문자열이 존재하는지에 대해 판별하기 위해서는
S : 어떠한 문자열 t : 찾고자 하는 문자열 이라고 한다면
if(S.find(t) != string::npos) 를 통해서 이것을 만족한다면 문자열이 있다고 판별할 수 있다.
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 31 32 33 34 35 36 37 38 39 40 41 | #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <cstring> #include <set> #include <queue> #include <stack> #include <map> #define MAX_N 100 #define INF 1e8 #define MOD 1000000007 typedef long long ll; using namespace std; string s; int main(){ cin >> s; int n; int ans= 0; cin >> n; for(int k=1;k<=n;k++){ string ss; string sss; cin >> ss; sss= ss; int len = ss.length(); for(int i=0;i<len;i++){ ss.push_back(sss[i]); } if((ss.find(s)) != string::npos){ ans++; } } cout << ans<<endl; } | cs |