Ai aici rezolvarea in C++
#include <iostream>
using namespace std;
int sumCif(int n)
{
int num = 0;
while (n != 0)
{
num += n % 10;
n /= 10;
}
return num;
}
int main()
{
int n, k, suma = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (sumCif(x) == k)
{
suma = suma + x;
}
}
cout << suma;
return 0;
}