http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3220
简单题,好久没写c++代码了,练习zoj,也学习c++.
#include <iostream> #include <cmath> using namespace std; const int ROW = 8; const int COLUMN = 6; char abacus[ROW][COLUMN]; int main(){ int cas; cin >> cas; int start; int end; int sum; while(cas--){ cin >> start >> end; sum = 0; for(int i = start; i <= end; i++){ sum += i; } for(int i = 0; i < ROW; i++){ for(int j = 0; j < COLUMN; j++){ cin >> abacus[i][j]; } } int getSum = 0; int times = 1; for(int i = COLUMN - 1; i >= 0; i--){ int thisSum = 0; if(abacus[0][i] == '|'){ thisSum = 5; } for(int j = 3; j < ROW; j++){ if(abacus[j][i] == '|'){ thisSum += (j - 3); break; } } getSum += thisSum * times; thisSum = 0; times *= 10; } if(sum == getSum){ cout << "No mistake" << endl; }else{ cout << "Mistake" << endl; } } }