蓝桥——六位排他平方数

题目:

代码:

// test.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<sstream>
#include <type_traits>
using namespace std;
//判断string是否每个都不同
bool judgeSelfNoSame(string s) {
    long long  i, j;
    for ( i = 0; i < s.length();i++) 
        for (j = 0; j < s.length(); j++) {
            if (s[i] == s[j] && i != j) return false;
        }
    return true;
}

bool judge2NoSame(string a, string b) {
    long long  i, j;
    for (i = 0; i < a.length(); i++)
        for (j = 0;j < b.length(); j++) {
            if (b[j] == a[i]) return false;
        }
    return true;
}

void l2s(long long a, string &s) {
    stringstream ss;
    ss << a;
    ss >> s;
}

int main()
{    
    string s;
    string pfs;
    for (long long i = 123456; i < 1000000; i++) {
        l2s(i, s);
        if (judgeSelfNoSame(s)) {
            l2s(i*i, pfs);
            if (judge2NoSame(s, pfs))cout << i << endl;
        }
    }
  return 0;
}

 

 

posted @ 2019-03-03 21:29  Kiss_the_rain  阅读(157)  评论(0编辑  收藏  举报