본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 11121 : Communication Channels

반응형

https://www.acmicpc.net/problem/11121

 

11121번: Communication Channels

The first line of the input consists of a single number T, the number of transmissions. Then follow T lines with the input and the output of each transmission as binary strings, separated by a single space. 0 < T ≤ 100 All inputs and outputs has length l

www.acmicpc.net

간단 구현문제였습니다.

📕 풀이방법

📔 입력 및 초기화

test case t, 문자열 a, b를 선언 후 적절히 입력받습니다.

📔 풀이과정

a, b의 문자를 확인해 하나만 달라도 ERROR입니다. 이에 대해 판별하는 isOK함수를 실행합니다.

📔 정답출력

isOK함수의 반환값을 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t;
string a, b;

string isOk(){
  for(int i = 0; i < a.size(); i++){
    if(a[i] != b[i]) return "ERROR\n";
  }
  return "OK\n";
}

int main(){
  cin >> t;
  while(t--){
    cin >> a >> b;
    cout << isOk();
  }
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.