Untitled

 avatar
Norms
c_cpp
4 years ago
685 B
17
Indexable
#include<bits/stdc++.h>
using namespace std;

int digitSum(int x){
    int sum = 0;
    while(x != 0){
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int main(){
    fstream fi,fo;
    vector<int> result;
    vector<int> data;
    int n,x;
    fi.open("DAYSOBD.INP",ios::in);
    fi >> n;
    for(int i = 0; i<n; i++){
        fi >> x;
        data.push_back(x);
    }
    fi.close();
    for(auto x : data){
        if(x % digitSum(x) == 0) result.push_back(x);
    }
    fo.open("DAYSOBD.OUT",ios::out);
    if(result.size() == 0) fo << -1;
    else{
        for(auto x : result) fo << x << " ";
    }
    fo.close();
    return 0;
}
Editor is loading...