計算零與非零的數量,並相減即可得解。
C++(0.012)
/*******************************************************/
/* UVa 12279 Emoogle Balance */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2013/01/21 */
/*******************************************************/
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int N;
int case_number = 1;
while( scanf("%d", &N) != EOF && N != 0 ){
int emoogle_balance = 0;
int event;
for( int i = 0 ; i < N ; i++ ){
scanf("%d", &event);
emoogle_balance += (event != 0)? 1 : -1;
}
printf( "Case %d: %d\n", case_number++, emoogle_balance );
}
return 0;
}