1 条题解
-
0
C :
#include <stdio.h> int main() { int sum[10000]={0}; int a,b,c,d,n,i,temp,s=0; scanf ("%d",&n); for (i=1000;i<=n;i++) { a=i/1000; temp=i%1000; b= temp/100; temp%=100; c=temp/10; temp%=10; d=temp; if (a%2!=0&&b%2!=0&&c%2!=0&&d%2!=0) { sum[i]=i; } s+=sum[i]; } printf ("%d",s); return 0; }
C++ :
#include <iostream> using namespace std; int main(){ int n,i,r = 0,g,s,b,q; cin>>n; for(i=1000;i<=n;i++){ q = i /1000; b = i / 100 % 10; s = i / 10 % 10; g = i % 10; if(q%2==1&&b%2==1&&s%2==1&&g%2==1){ // cout<<i<<endl; r = r + i; } } cout<<r; }
Java :
import java.util.Scanner; public class Main{ public static void main(String[] agrs){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int s = 0; for(int i = 1000;i <= n;i++){ if((i / 1000 % 2 != 0) && (i / 100 % 10 % 2 != 0) && (i / 10 % 10 % 2 != 0) && (i % 10 % 2 != 0)){ s = s + i; } } System.out.println(s); } }
Python :
n = int(input()) su = 0 for i in range(1000, n + 1): q = i // 1000 % 10 b = i // 100 % 10 s = i // 10 % 10 g = i // 1 % 10 if q % 2 == 1 and b % 2 == 1 and s % 2 == 1 and g % 2 == 1: su = su + i print(su)
- 1
信息
- ID
- 2627
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者