UVALive 4853 Emoogle Balance

題意:題目很長,其實主要就是題中加粗的那個公式和輸入輸出。給n個數,用非零數的個數減去零的個數。

水題啦~

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[1005];

int main()
{
    int ans, cnt = 1, n;
    while(~scanf("%d", &n))
    {
        ans = 0;
        if(n == 0)
            break;
        int b;
        for(int i = 0; i < n; i++)
        {
            scanf("%d", &b);
            if(b == 0)
                ans--;
            else
                ans++;
        }
        printf("Case %d: %d\n", cnt++, ans);
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章