跳到正文

题解

题解:P15106 [ICPC 2025 LAC] LED Counter

#SUSPENDED#约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年1月29日
收录
2026年1月29日
更新
2026年11月17日
篇幅
约 2 分钟
获赞
1
题目
P15106

版本

  1. v3当前
  2. v2
  3. v1

蒟蒻的第一篇题解,求过。

题目大意

就是给你每个 LED 灯的状态,让你判断为哪个数字,如不是数字,对应的位置输出*号。

思路

打表。

用一个 string 的二维数组存储 00 至 99 的字符形态,然后遍历输入的每一个字符串所代表的对应的 LED 灯,判断为哪一个数字,然后存到 ansans 数组里,就搞定了。

AC code
C++
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
string num,ans[maxn];
string nn[10] = {
    "1110111",
    "0000011",
    "0111110",
    "0011111",
    "1001011",
    "1011101",
    "1111101",
    "0010011",
    "1111111",
    "1011111"
};
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>num;
        vector<int>c;
        for(int d=0;d<10;d++){
            bool x=true;
            for(int j=0;j<7;j++){
                if(num[j]=='G'||num[j]=='g'){
                    int q=nn[d][j]-'0';
                    int w=(num[j]=='G')?1:0;
                    if(q!=w){
                        x=false;
                        break;
                    }
                }
            }
            if(x){
                c.push_back(d);
            }
        }
        if(c.size()==1){
            ans[i-1]='0'+c[0];
        }else{
            ans[i-1]='*';
        }
    }
    for(int i=0;i<n;i++)cout<<ans[i];
    return 0;
}

AC记录

原文