1 条题解

  • 0
    @ 2023-6-11 12:17:08

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int a[1000],n,x,c = 0,s = 0,t,i;
    	bool f;
    	cin>>n;
    	for(i = 0;i < n;i++){
    		cin>>a[i];
    	}
    	cin>>x;
    	
    	for(i = 0;i < n;i++){
    		f = false;
    		t = a[i];
    		while(t != 0){
    			if(t % 10 == x){
    				f = true;
    				break;
    			}
    			t = t / 10;
    		}
    		
    		if(f == true){
    			c++;
    			s = s + a[i];
    		}
    	}
    	
    	cout<<c<<" "<<s<<endl;
    }
    
    
    

    Python :

    n = int(input())
    s = input().split()
    x = int(input())
    c = 0
    su = 0
    for i in s:
        k = int(i)
        q = k // 1000 % 10
        b = k // 100 % 10
        s = k // 10 % 10
        g = k // 1 % 10
        if q == x or b == x or s == x or g == x:
            c += 1
            su += k
    print(c, end=' ')
    print(su)
    
    • 1

    信息

    ID
    2345
    时间
    1000ms
    内存
    16MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者