64,642
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
#include <math.h>
bool isNumBitSame(int , int );
bool isNumHasSame(int);
void intToArray(int , int *);
int main()
{
using namespace std;
int num1, num2, num3;
int num1Array[3], num2Array[3], num3Array[3];
for (num1 = 100; num1 < 329; num1++)
{
num2 = num1 * 2;
if (!isNumBitSame(num1, num2))
{
num3 = num1 * 3;
if (!isNumBitSame(num1, num3) && !isNumBitSame(num2, num3))
{
if (!isNumHasSame(num1) && !isNumHasSame(num2) && !isNumHasSame(num3))
{
cout << num1 << " " << num2 << " " << num3 << " " << endl;
}
}
}
}
return 0;
}
bool isNumBitSame(int a, int b)
{
using namespace std;
int ap[3], bp[3];
intToArray(a, ap);
intToArray(b, bp);
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if (ap[i] == bp[j])
return true;
return false;
}
bool isNumHasSame(int a)
{
int ap[3];
intToArray(a, ap);
int i, j;
for (i = 0; i < 3; i++)
for (j = i+1; j < 3; j++)
if (ap[i] == ap[j])
return true;
for (i = 0; i < 3; i++)
if (ap[i] == 0)
return true;
return false;
}
void intToArray(int a, int *aArray)
{
int i;
for (i = 0; i < 3; i++)
{
aArray[i] = a / int(pow(10, 2 - i));
a = a - aArray[i] * int(pow(10, 2 - i));
}
}
//192 384 576
//219 438 657
//273 546 819
//327 654 981
新手代码,多多指教// fuck project main.go
package main
import (
"fmt"
"strconv"
"strings"
)
type result struct {
abc int
def int
ghi int
}
func (r result) String() string {
return fmt.Sprintf("abc:%d,bcd:%d,ghi:%d", r.abc, r.def, r.ghi)
}
func fuck() []result {
var buffer []result
a := 123
for {
a3 := a * 3
if a3 > 987 {
break
}
stra := strconv.Itoa(a)
strb := strconv.Itoa(a * 2)
strc := strconv.Itoa(a3)
if func(str string) bool {
state := true
for i := 1; i <= 9; i++ {
if false == strings.Contains(str, strconv.Itoa(i)) {
state = false
break
}
}
return state
}(stra + strb + strc) {
result := new(result)
result.abc = a
result.def = a * 2
result.ghi = a3
buffer = append(buffer, *result)
}
a++
}
return buffer
}
func main() {
buffer := fuck()
for _, data := range buffer {
fmt.Println(data)
}
}
凑热闹
import java.util.Arrays;
public class Test{
public static void main(String[] args){
int start = 123; //最小的数字
int end = 987;//最大的数字
int result = 0;
for(result = start ; result <= end ; result ++){
if(check(result)){
System.out.println(result);
}
}
}
private static boolean check(int index){
int second = 2 * index;
int third = 3 * index;
String content = index + "" + second + third;
String[] strs = content.split("");//将字符串拆散成数组
Arrays.sort(strs); //排序数组
String result = "";
for(String str : strs){
result += str;
}
return result.equals("123456789");
}
}
import java.util.Arrays;
public class Test{
public static void main(String[] args){
int start = 123; //最小的数字
int end = 987;//最大的数字
int result = 0;
for(result = start ; result <= end ; result ++){
if(check(result)){
break;
}
}
System.out.println(result);
}
private static boolean check(int index){
int second = 2 * index;
int third = 3 * index;
String content = index + "" + second + third;
String[] strs = content.split("");//将字符串拆散成数组
Arrays.sort(strs); //排序数组
String result = "";
for(String str : strs){
result += str;
}
return result.equals("123456789");
}
}
if (abc>333) break;
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<char> P(9);
vector<char>::iterator b,e;
b=P.begin();
e=P.end();
for (int i=0;i<9;i++) P[i]=i+1;
do {
int abc,def,ghi;
abc=P[0]*100+P[1]*10+P[2];
def=P[3]*100+P[4]*10+P[5];
ghi=P[6]*100+P[7]*10+P[8];
if (abc*2==def && abc*3==ghi) printf("%d %d %d\n",abc,def,ghi);
} while (next_permutation(b,e));
return 0;
}
//192 384 576
//219 438 657
//273 546 819
//327 654 981
//
int ct[10];
bool rep(int n){
if(n>999&&n<100) return true;
while(n){
int k=n%10;
if(++ct[k]!=1) return true;
n /=10;
}
return false;
}
void solve()
{
for(int i=100;i<1000/3;i++){
memset(ct,0,sizeof ct);
if(rep(i)||rep(i*2)||rep(i*3)) continue;
printf("%d+%d=%d\n",i,i*2,i*3);
}
}
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
vector<char> P(9);
vector<char>::iterator b,e;
b=P.begin();
e=P.end();
for (int i=0;i<9;i++) P[i]=i+1;
do {
double abc,def,ghi;
abc=P[0]*100.0+P[1]*10.0+P[2];
def=P[3]*100.0+P[4]*10.0+P[5];
ghi=P[6]*100.0+P[7]*10.0+P[8];
if (fabs(def/abc-2.0)<0.0001 && fabs(ghi/abc-3.0)<0.0001) printf("%lg %lg %lg\n",abc,def,ghi);
} while (next_permutation(b,e));
return 0;
}
//192 384 576
//219 438 657
//273 546 819
//327 654 981
//