1 条题解

  • 0
    @ 2026-4-1 19:52:08

    我也是数学题吗 对

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        string str;
        cin>>str;
        int n=str.size();
        set<int>a;
        priority_queue<int,vector<int>,greater<int>>b;
        for(int i=0;i<n;i++){
            if(str[i]<='9'&&str[i]>='0'&&str[i]!='7'&&str[i]!='0'){
                a.insert(str[i]-'0');
                if(a.size()==8){
                    break;
                }
            }
        }
        for(auto i:a){
            long long h=0;
            if(i==1){
                b.push(i);
                continue;
            }
            else if(i==2&&(str[n-1]-'0')%2==0){
                b.push(i);
                continue;
            }
            else if(i==3){
                for(int i=0;i<n;i++){
                h+=str[i]-'0';
            }
            if(h%3==0){
                b.push(i);  
            }
            continue;
            }
            else if(i==4){
                if(n>=3){
                    int k=(str[n-1]-'0')+(str[n-2]-'0')*10+(str[n-3]-'0')*100;
                    if(k%4==0){
                        b.push(i);
                    }
                }
                else if(n==2){
                    int k=(str[n-1]-'0')+(str[n-2]-'0')*10;
                    if(k%4==0){
                        b.push(i);
                    }
                }
                else if(n==1){
                    if((str[n-1]-'0')%4==0){
                        b.push(i);
                    }
                }
                continue;
            }
            else if(i==5){
                if((str[n-1]-'0'==i)||((str[n-1]-'0'==0)&&(n>1))){
                    b.push(i);
                }
                continue;
            }
            else if(i==8){
                if(n>=4){
                    int k=(str[n-1]-'0')+(str[n-2]-'0')*10+(str[n-3]-'0')*100+(str[n-4]-'0')*1000;
                    if(k%8==0){
                        b.push(i);
                    }
                }
                else if(n==3){
                    int k=(str[n-1]-'0')+(str[n-2]-'0')*10+(str[n-3]-'0')*100;
                    if(k%8==0){
                        b.push(i);
                    }
                }
                else if(n==2){
                    int k=(str[n-1]-'0')+(str[n-2]-'0')*10;
                    if(k%8==0){
                        b.push(i);
                    }
                }
                else if(n==1){
                    if((str[n-1]-'0')%8==0){
                        b.push(i);
                    }
                }
                continue;
            }
            else if(i==6){
                if((str[n-1]-'0')%2==0){
                    for(int i=0;i<n;i++){
                            h+=str[i]-'0';
                    }
                if(h%3==0){
                    b.push(i);  
                }
                    continue;
                }
            }
            else{//9
                int sum=0;
                for(char c:str){
                    sum+=c-'0';
                }
                if(sum%9==0){
                    b.push(i);
                }
            }
            }
        
        
        
        while(!b.empty()){
            cout<<b.top()<<' ';
            b.pop();
        }
        
        return 0;
    }
    

    信息

    ID
    11
    时间
    1000ms
    内存
    128MiB
    难度
    9
    标签
    递交数
    18
    已通过
    3
    上传者