长安大学第二届ACM校赛题解 A Count Circles

Count Circles

发布时间: 2017年4月19日 15:09 最后更新: 2017年4月19日 16:04 时间限制: 1000ms 内存限制: 128M

描述
Stupid Aguin feels confused while reading. The book shows following equations:
6=9 , 8=1010 , 144=75 , 690=801
Stupid Aguin doesn’t know why and he asks RoyYuan for help. RoyYuan tells Aguin that he only needs to count circles in each number. Notice that 0 , 6 and 9 have one circle, and 8 has two circles. For example, both 690 and 801 have 3 circles, so 690 = 801.

However, Aguin is too stupid to count circles in each number, please help him.

输入
The first line contains an integer number T, the number of test cases.

i-th of each next T lines contains an integer number x(0≤x≤109).

输出
For each test case print a number, the number of circles in x.

样例输入1 复制
8
6
9
8
1010
144
75
690
801

样例输出1
1
1
2
2
0
0
3
3

题目思路:字符串统计一下就好

#include 
#include

using namespace std;

int main() {
    string num;
    int cases__;
    cin >> cases__;
    while (cases__--) {
        cin >> num;
        int R__ = 0;
        for (string::iterator i = num.begin(); i != num.end(); i++) {
            if (*i == '0' || *i == '6' || *i == '9')
                R__++;
            if (*i == '8')
                R__ += 2;
        }
        cout << R__ << endl;
    }
    return 0;
}

你可能感兴趣的:(长安大学第二届ACM校赛题解 A Count Circles)