洛谷 (暴力)P1618 三连击(升级版)
忽略了有比值数为0的情况,考虑不周
经常忘记写无解的情况
#include<bits/stdc++.h>
using namespace std;
int loc = 0;
int check(int a,int b,int c){
int t = 0;
int d[10];
while(a){
d[t++] = a%10;
a/=10;
}
while(b){
d[t++] = b%10;
b/=10;
}
while(c){
d[t++] = c%10;
c/=10;
}
sort(d,d+t);
for(int i=0; i<t-1; i++)if(d[i]==0||d[i]==d[i+1])return 0;
return 1;
}
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(!a || !b || !c){
printf("No!!!");
return 0;
}
int n = a+b+c;
for(int i=100; i<=500; i++){
int pa = i;
int pb = pa*((double)b/a);
int pc = pa*((double)c/a);
if(pa<=1000&&pb<=1000&&pc<=1000&&check(pa,pb,pc)){
printf("%d %d %d\n",pa,pb,pc);
loc = 1;
}
}
if(!loc)printf("No!!!");
return 0;
}