[UVa #12279] Emoogle Balance

tolelom·2022년 7월 5일
0

UVa

목록 보기
12/20

문제 설명

문제 링크
설명은 장황한데 배열 순회하는 문제

알고리즘

nn개 입력을 받아서 0이면 -1, 0이 아니면 +1 해주는 연산해서 결과값 도출

코드

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000

int t;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    for (int tc = 1; ; tc++){
        int n;
        cin >> n;

        if (n == 0) break;

        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            int t; cin >> t;
            if (t == 0) ans--;
            else ans++;
        }

        cout << "Case " << tc << ": " << ans << '\n';
    }
}
profile
이것 저것 작성하는 기술 블로그

0개의 댓글