Git Product home page Git Product logo

Comments (8)

ruoguang avatar ruoguang commented on May 4, 2024 2
public class Test {
    public static void main(String[] args) {
        for (int i = 10000; i < 99999; i++) {
            int a = i / 10000;
            int b = i / 1000 % 10;
            int c = i / 100 % 10;
            int d = i / 10 % 10;
            int e = i % 10;
            HashSet<Integer> set = new HashSet<Integer>();
            set.add(a);
            set.add(b);
            set.add(c);
            set.add(d);
            set.add(e);
            if (set.size() == 5) {
                for (int j = 1; j < 10; j++) {
                    if (i * j == (e * 10000 + d * 1000 + c * 100 + b * 10 + a)) {
                        System.out.println(a + "," + b + "," + c + "," + d + "," + e + "," + j);
                    }
                }
            }

        }
    }
}

from leetcode.

bryceustc avatar bryceustc commented on May 4, 2024 2

因为是五个不同的数字,其实循环次数可以再减少一些,就从12345-98765进行搜索

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
	for( int i=12345; i<=98765; i++)
	{
		int a = i / 10000;
		int b = i % 10000 / 1000;
		int c = i % 10000 % 1000 / 100;
		int d = i % 10000 % 1000 % 100 / 10;
		int e = i % 10;
		if(a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e)
		{
		    int j = e * 10000 + d * 1000 + c * 100 + b * 10 + a;
		    if( j % i == 0 )
		    {
			cout << i << "*" << (j/i) << "=" << j <<endl;
		    }
                }
	}
	return 0;
}

from leetcode.

azl397985856 avatar azl397985856 commented on May 4, 2024

我这里给出一种“大人的”解法,思路就是从所有可能满足条件的数中暴力搜索即10000 - 99999,每一个数字我都去求它的回文数字, 并且观察每一位是不是否不同,如果都不同,我就用回文数除以原来的数字,得出的数字是整数(确切的说是一位整数)就将其返回。

先说答案, 答案是 21978 * 4 = 87912

为了方便理解,我这里做了两次循环,其实可以放到一起, 大神请忽略~

function reversedNumber(n) {
  let r = 0;

  while (n >>> 0 !== 0) {
    r = r * 10 + (n % 10);
    n = (n / 10) >>> 0;
  }

  return r;
}

function hasDuplicated(n) {
  const  used = {};

  while (n >>> 0 !== 0) {
    n = (n / 10) >>> 0;
    if (used[n % 10]) return true;
    used[n % 10] = true;
  }

  return false;
}
function t() {
  let n = 0;
  for (let i = 10000; i < 100000; i++) {
    if(hasDuplicated(i)) continue;
    n = reversedNumber(i);
    if (n / i === (n / i) >>> 0) return `${i} * ${n / i} = ${n}`;
  }
}

console.log(t()); // 21978 * 4 = 87912

from leetcode.

can350925 avatar can350925 commented on May 4, 2024

from leetcode.

azl397985856 avatar azl397985856 commented on May 4, 2024

from leetcode.

stale avatar stale commented on May 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from leetcode.

mayali123 avatar mayali123 commented on May 4, 2024

#include<stdio.h>
int main()
{
int a,b,c,d,e,f,i;
for(i=10000;i<=99999;i++)
for(f=1;f<=9;f++)
{
a=i%10;
b=i/10%10;
c=i/100%10;
d=i/1000%10;
e=i/10000;
if(if==a10000+b1000+c100+d*10+e&&f!=a&&f!=b&&f!=c&&f!=d&&f!=e)
if(a!=b&&a!=c&&a!=d&&a!=e&&b!=c&&b!=d&&b!=e&&c!=d&&c!=e&&d!=e)
printf("%d %d\n",i,f);
}
}
结果是21978 *4=87912

from leetcode.

stale avatar stale commented on May 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from leetcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.