fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 11158 (C++) Angry Grammar Nazi
최초 업로드: 2025-09-20 18:34:01
최근 수정 시간: 2025-09-20 18:34:01
게시자: rlatjwls3333
카테고리: 백준
조회수: 4
# [Bronze I] Angry Grammar Nazi [문제 링크](https://www.acmicpc.net/problem/11158) ## 문제 설명 <p>Your friend is what we can call a grammar nazi. He spends a lot of time on popular internet discussion forums. Unfortunately, he has a bad temper and loses his mind whenever someone incorrigibly befouls the English language, with unrelenting violations of grammatical and ortographic rules.</p> <p>In order to avoid smashed keyboards, monitors and coffee-cup holders, you advice your friend to momentarily stop reading and count to ten each time he becomes angry, instead of smashing something.</p> <p>Your friend becomes angry whenever he reads the following words or sequences of words:</p> <ul> <li>“u”, “ur” instead of “you”, “your”.</li> <li>“would of”, “should of” instead of “would have”, “should have”.</li> <li>“lol” instead of “haha”. In fact he becomes angry even when a word contains “lol” as a substring.</li> </ul> <p>You decide to write a computer program that reads sentences one by one, and for each sentence calculates how many times your friend will have uttered a number after reading said sentence. Your friend does not read out loud, so numbers that are part of the input-sentences should not be counted.</p> ## 입력 <p>The first line of the input consists of a single integer T, the number of test cases. The following T lines each contain one sentence; that is, one or more words separated by space.</p> <ul> <li>0 < T ≤ 50</li> <li>A sentence consists of at most 100 characters, including spaces.</li> <li>A word consists only of lower case letters between a and z, inclusively.</li> <li>Two adjacent words are separated by exactly one space, and a sentence never has leading or trailing spaces.</li> </ul> ## 출력 <p>For each test case, output how many times your friend have said a number after reading the sentence.</p> ## 풀이 u, ur, lol, would of, should of에 대해 전부 case-work 해주면 됩니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; cin.ignore(); while(t--) { string s; getline(cin, s); int n = s.length(); int cnt=0; bool chk=false; for(int i=0;i<n;i++) { if(s[i]==' ' && chk) { chk=false; cnt+=10; } else if((i-1<0 || s[i-1]==' ') && (i+1>=n || s[i+1]==' ') && s[i]=='u') { cnt+=10; i++; } else if((i-1<0 || s[i-1]==' ') && (i+2>=n || s[i+2]==' ') && i+1<n && s[i]=='u' && s[i+1]=='r') { cnt+=10; i+=2; } else if((i-1<0 || s[i-1]==' ') && (i+9>=n || s[i+9]==' ') && i+8<n && s[i]=='s' && s[i+1]=='h' && s[i+2]=='o' && s[i+3]=='u' && s[i+4]=='l' && s[i+5]=='d' && s[i+6]==' ' && s[i+7]=='o' && s[i+8]=='f') { cnt+=10; i+=9; } else if((i-1<0 || s[i-1]==' ') && (i+8>=n || s[i+8]==' ') && i+7<n && s[i]=='w' && s[i+1]=='o' && s[i+2]=='u' && s[i+3]=='l' && s[i+4]=='d' && s[i+5]==' ' && s[i+6]=='o' && s[i+7]=='f') { cnt+=10; i+=8; } else if(i+2<n && s[i]=='l' && s[i+1]=='o' && s[i+2]=='l') { chk=true; } } if(chk) cnt+=10; cout << cnt << '\n'; } } ```