【每日一题】蓝桥杯历年真题题解 -数的分解
1、Java组
public class Main {
static int check(int x)
{
while(x != 0)
{
int now = x % 10;
if(now == 2 || now == 4) return 0;
x = x / 10;
}
return 1;
}
public static void main(String[] args) {
int ans = 0;
for(int i = 1;i <= 2019;i++)
for(int j = i + 1;j <= 2019;j++)
{
int k = 2019 - i - j;
if(check(i) == 1 && check(j) == 1 && check(k) == 1 && i < j && j < k) ans++;
}
System.out.println(ans);
}
}
2、C&C++组
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 20190325;
bool check(ll x){
if(x <= 0) return false;
while(x){
int now = x % 10;
if(now == 2 || now == 4) return false;
x /= 10;
}
return true;
}
int main()
{
int ans = 0;
for(int i = 1;i <= 2019;i++){
for(int j = i + 1;j <= 2019;j++){
int k = 2019 - i - j;
if(check(i) && check(j) && check(k) && i < j && j < k ) ans++;
}
}
cout << ans << endl;
return 0;
}

添加 家长论坛微信
全部 0条评论