| |

VerySource

 Forgot password?
 Register
Search
Author: 张阿大

Please masters to help write an algorithm !!

[Copy link]

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-6-20 17:00:01
| Show all posts
Okay, great, thank you, and all the same friends who answered questions!!
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Egypt

Post time: 2020-6-20 21:30:01
| Show all posts
import java.util.Scanner;

public class Test34 {
public static void Cal(long max) {
String str34[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M",
"N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };

String result = "";
String tmpStr = "";
long tmpI;
int maxWS = 1;
int tmpWS;
tmpI = max;
// First judge the 34 digits of the input number
while (tmpI / 34> 34) {
maxWS++;
tmpI = tmpI / 34;
}
// increasing output
for (int i = 0; i <max; i++) {
tmpI = i;
tmpWS = maxWS;
result = "";
while (tmpWS> 0) {
tmpStr = str34[(int) Math.floor(tmpI
/ Math.pow(34, (double) tmpWS))];
result = result + tmpStr;
if (tmpStr != "0") {
tmpI = tmpI- (new Double(Math.floor(tmpI/ Math.pow(34, (double) tmpWS)))).longValue() * (new Double(Math.pow(34, (double) tmpWS))) .longValue();
}
tmpWS--;
}
result = result + str34[(int) i% 34];
System.out.println(result);
}

}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
long num = in.nextLong();
if (num == 0) {
System.exit(0);
}
Cal(num);
}
}
}

Enter a decimal number arbitrarily, call the Cal() method to print the 34 decimal number incremented from 1 to the decimal number
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-21 09:30:01
| Show all posts
public class TestSn {

    public static final char EXCEPT_CHAR_I ='I';
    public static final char EXCEPT_CHAR_O ='O';
    public static final char REVERT_CHAR ='[';

    public TestSn() {

    }

    public String getNextSn(String sn) {

        if (sn == null || sn.equals("")) {
            sn = "0000";
        }

        char[] snChars = sn.toCharArray();
        snChars[3] = (char)(snChars[3] + 1);
        for (int i = snChars.length-1; i >= 0; i--) {
            if (snChars[i] ==':') {
                snChars[i] ='A';
                break;
            }
            if (snChars[i] == EXCEPT_CHAR_I) {
                snChars[i] ='J';
                break;
            }
            if (snChars[i] == EXCEPT_CHAR_O) {
                snChars[i] ='P';
                break;
            }

            if (i == 0) {
                if (snChars[i] == REVERT_CHAR) {
                    return "0000";
                }
            }
            else {
                if (snChars[i] == REVERT_CHAR) {
                    snChars[i] = '0';
                    snChars[i-1] = (char)(snChars[i-1] + 1);
                }
            }
        }

        return new String(snChars);
    }

    public static void main(String[] args) {

        TestSn test = new TestSn();
        String sn = "0000";
        int times = 0;
        while (!sn.equals("ZZZZ")) {
            times++;
            sn = test.getNextSn(sn);
            System.out.println(times + ":" + sn);
        }
    }

}
Reply

Use magic Report

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-6-23 13:15:01
| Show all posts
Replying tocdl30000, your input 1157, 1158 will appear java.lang.ArrayIndexOutOfBoundsException: 34
at com.omiss.gs.code.Test34.Cal(Test34.java:31)
at com.omiss.gs.code.Test34.main(Test34.java:54)
Exception in thread "main"
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-7-3 19:30:01
| Show all posts
Optimize it:)
----------------------------

public class TestSn {

    public static final char FIRST_SECT_START = '0';
    public static final char FIRST_SECT_END = '9';
    public static final char SECOND_SECT_START ='A';
    public static final char SECOND_SECT_END ='Z';
    public static final char EXCEPT_CHAR_I ='I';
    public static final char EXCEPT_CHAR_O ='O';
    public static final String CYCLE_SN_FIRST = "0000";

    public TestSn() {

    }

    public String getNextSn(String sn) {

        if (sn == null || sn.equals("")) {
            sn = CYCLE_SN_FIRST;
        }

        char[] snChars = sn.toCharArray();
        snChars[3] = (char)(snChars[3] + 1);
        for (int i = snChars.length-1; i >= 0; i--) {
            if (snChars[i] == FIRST_SECT_END + 1) {
                snChars[i] = SECOND_SECT_START;
                break;
            }
            if (snChars[i] == EXCEPT_CHAR_I) {
                snChars[i] = EXCEPT_CHAR_I + 1;
                break;
            }
            if (snChars[i] == EXCEPT_CHAR_O) {
                snChars[i] = EXCEPT_CHAR_O + 1;
                break;
            }

            if ((snChars[i] >= FIRST_SECT_START&&snChars[i] <= FIRST_SECT_END)
                || (snChars[i] >= SECOND_SECT_START&&snChars[i] <= SECOND_SECT_END)) {
                break;
            }

            if (i == 0) {
                if (snChars[i] == SECOND_SECT_END + 1) {
                    return CYCLE_SN_FIRST;
                }
            }
            else {
                if (snChars[i] == SECOND_SECT_END + 1) {
                    snChars[i] = FIRST_SECT_START;
                    snChars[i-1] = (char)(snChars[i-1] + 1);
                }
            }
        }

        return new String(snChars);
    }

    public static void main(String[] args) {

        TestSn test = new TestSn();
        String sn = "0000";
        int times = 0;
        while (!sn.equals("ZZZZ")) {
            times++;
            sn = test.getNextSn(sn);
            System.out.println(times + ":" + sn);
        }
    }
}
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-10 12:45:01
| Show all posts
class Test
{

public static void main(String[] args)
{
String[] strAr= {"0","1","2","3","4","5","6","7","8","9","A", "B","C","D","E","F","G","H","J","K","L","M","N","P ","Q","R","S","T","U","V","W","X","Y","Z"};
String b = "";
int le = strAr.length;
int bLength = le*le*le*le;
System.out.println("Start" + le);
for (int a=0;a <bLength; a++)
{
  System.out.println("this is over code :" strAr[(a%(le*le*le))/(le*le*le)]+ str[(a%(le*le))/(le *le)]+strAr[(a%le)/le]+ strAr[a%le];
}
}
}

Haven't tested it? Try it
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-10 18:15:01
| Show all posts
Sorry that the above is wrong.
class Test
{

public static void main(String[] args)
{
String[] strAr= {"0","1","2","3","4","5","6","7","8","9","A", "B","C","D","E","F","G","H","J","K","L","M","N","P ","Q","R","S","T","U","V","W","X","Y","Z"};
String b = "";
int le = strAr.length;
int bLength = le*le*le*le;
System.out.println("Start" + le);
for (int a=0;a <le*le*le*le; a++)
{
  System.out.println("this is over code :" + strAr[(a%(le*le*le*le))/(le*le*le)]+ strAr[(a%(le*le*le ))/(le*le)]+strAr[(a%(le*le))/le]+ strAr[a%le]);
}
}
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-13 00:00:01
| Show all posts
hehe hehe master!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-14 19:15:01
| Show all posts
Has the problem been solved? I'm in an internet cafe now, I can't read it. I didn't test it yesterday, I got it wrong, huh!
Reply

Use magic Report

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-7-20 00:45:01
| Show all posts
The problem is solved, thank you very much for your attention!!!!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list