Programming/백준
[BOJ] 1316번 그룹 단어 체커
M0ca
2018. 3. 24. 10:18
반응형
vector로 find해서 찾으려 했는데 뇌과부하 와서 배열로 풀었다.
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 42 43 44 45 46 47 48 49 | #include <iostream> using namespace std; int main() { int n; int cnt = 0; char voca[101]; //cout << "입력받을 횟수: "; cin >> n; for(int i=0;i<n;i++) { bool check[26]{false,}; cin.ignore(); cin.get(voca,100); for(int j=0;voca[j]!='\0';j++) { //cout << "voca[j]: " << static_cast<int>(voca[j] - 97) << endl; //cout << "check[static_cast<int>(voca[j] - 97)]: " << check[static_cast<int>(voca[j] - 97)] << endl; if(check[static_cast<int>(voca[j] - 97)] == false) { check[static_cast<int>(voca[j] - 97)] = true; //cout << "check[static_cast<int>(voca[j] - 97)]: " << check[static_cast<int>(voca[j] - 97)] << endl; } else if(check[static_cast<int>(voca[j] - 97)] == true) { //cout << "voca[j-1]" << ' ' << voca[j-1] << ' ' << "voca[j]" << ' ' << voca[j] << endl; if(voca[j-1] == voca[j]) { //cout << "sequence voca\n"; } else { //cout << "unsequnce voca\n"; break; } } if(voca[j+1] == '\0') cnt++; } //cout << endl; } //cout << "cnt: " << cnt << endl; cout << cnt << endl; return 0; } | cs |
반응형