1 solutions
-
0
C++ :
#include <bits/stdc++.h> using namespace std; int main(){ int a[10000],x,g,s,b,q,i,r = 0,c = 0,n; int t[10000],k = 0; cin>>x>>n; for(i = 0;i < n;i++){ cin>>a[i]; g = a[i] % 10; s = a[i] / 10 % 10; b = a[i] / 100 % 10; q = a[i] / 1000; if(g + s + b + q == x){ t[k] = a[i]; r = r + t[k]; k++; } } sort(t,t+k); cout<<r<<" "<<k<<endl; for(i = 0;i < k;i++){ cout<<t[i]<<" "; } }
Python :
def swh(n): s=list(map(int,str(n))) return sum(s); m,n=list(map(int,input().split())) s1=list(map(int,input().split())) s2=[item for item in s1 if swh(item)==m] print(sum(s2),len(s2)) s2.sort() for item in s2: print(item,end=" ")
- 1
Information
- ID
- 10446
- Time
- 1000ms
- Memory
- 32MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By