작성일 :

문제 링크

30045번 - ZOAC 6

설명

n개의 문장이 주어질 때, 각 문장에 01 또는 OI가 포함되어 있으면 이모티콘을 추가하는 문제입니다.


전체 추가 횟수를 출력합니다.


접근법

각 문장을 읽어 01 또는 OI가 포함되는지 확인합니다. 포함되면 개수를 1 증가시킵니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var cnt = 0;
    for (var i = 0; i < n; i++) {
      var s = Console.ReadLine()!;
      if (s.Contains("01") || s.Contains("OI"))
        cnt++;
    }
    Console.WriteLine(cnt);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    if (s.find("01") != string::npos || s.find("OI") != string::npos)
      cnt++;
  }
  cout << cnt << "\n";

  return 0;
}