题解:P15106 [ICPC 2025 LAC] LED Counter

· · 题解

题目大意

给你 n 个长度为 7 的字符串,每一个字符都是一个 LED 管,问对于每个字符串是否能只构成一个数字。

题目分析

AC代码:

#include <bits/stdc++.h>
using namespace std;
string led[10] = {"GGGgGGG","gggggGG","gGGGGGg","ggGGGGG","GggGgGG","GgGGGgG", "GGGGGgG","ggGggGG","GGGGGGG","GgGGGGG"};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    while (n--){
        string s;
        cin >> s;
        int cnt = 0,ans;
        for (int i = 0;i < 10;i++){
            bool flag = true;
            for (int j = 0;j < 7;j++){
                if (!(s[j] == led[i][j] or s[j] == '+' or s[j] == '-')) flag = false;
            }
            if (flag){
                cnt++;
                ans = i;
            }
        }
        if (cnt == 1) cout << ans;
        else cout << '*';
    }
    return 0;
}