| |

VerySource

 Forgot password?
 Register
Search
View: 3034|Reply: 29

Please masters to help write an algorithm !!

[Copy link]

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-2-6 18:00:01
| Show all posts |Read mode
problem:

Starting from 0001, each time you add 1 to 0009, add 1 to become 000A, add 1 to 000B, and then add 1 to 000Z, then add 1 and the tens place becomes 1, that is, 0010, and then add 1, then Become 0011, and then add until 0019, and then add 1 to 001A, and then add until 001Z, so if you add 1 each time, eventually it becomes ZZZZ, then the algorithm runs out. (Note: the letters 'O' and 'I' don't, because it is too much like 0 and 1) !! Thank you very much !!!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-31 14:45:01
| Show all posts
class Test
{

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

if (a <le)
{
b = "000" + strAr [a];
} else if (a <le * 2)
{
b = "00" + strAr [a-le] + "Z";
} else if (a <le * 3)
{
b = "0" + strAr [a-le * 2] + "ZZ";
} else if (a <le * 4)
{
b = strAr [a-le * 3] + "ZZZ";
}

System.out.println ("this is over code:" + b);
}
}
}
Reply

Use magic Report

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-6-9 05:15:01
| Show all posts
Upstairs, wrong, the result should be like this (the one on the left is decimal, and the right is 34):

0: 0
1: 1
twenty two
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: A
11: B
12: C
13: D
14: E
15: F
16: G
17: H
18: J
19: K
20: L
21: M
22: N
23: P
24: Q
25: R
26: S
27: T
28: U
29: V
30: W
31: X
32: Y
33: Z
34: 10
35: 1A
....
1156: ZZ
Trouble, think again, thank you very much!
Reply

Use magic Report

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-6-9 16:45:02
| Show all posts
Let me add that, in fact, it is to write a hexadecimal algorithm, but the hexadecimal is changed to 34 hexadecimal

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" };
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-10 14:30:01
| Show all posts
I just wrote it, take a look, will it work

class Test
{

public static void main(String[] args)
{
String[] strAr= {"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 num = "0000";
String ge="";
String shi="";
String bai="";
String qian="";
int s=0;
int genum=0,shinum=0,bai=0,qian=0;
int length=strAr.length();
while(true){
s++;
genum++;
if(genum<length){
num=num.subString(1,3)+geunm.toString;
}else{
genum=0;
shinum++;
if(shinum<length){
num=num.subString(1,2)+shinum.toString+"0";
}else{
shinum=0;
bainum++;
if(shinum<length){
num=num.subString(1,1)+bainum.toString+"00";
}else{
bainum=0;
qiannum++;
if(qiannum<length){
num=qiannum.toString+"000";
}else{
break;
}
}
}
}
System.out.println(s+":"+gennum);
}
}
}
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-10 16:45:01
| Show all posts
I am also a novice and may need to debug
Registered just now and engaged in a long time
Reply

Use magic Report

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-6-12 21:30:02
| Show all posts
Fainted, my dear friend upstairs, the editing is not enough, the variables String bai="";String qian="";int genum=0,shinum=0,bai=0,qian=0; and subString (), It should be substring();
Reply

Use magic Report

1

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-6-13 22:15:01
| Show all posts
Let me add that, in fact, you don’t need to consider the string "0000", as long as you pass in a number, such as 34, it becomes 10, such as input 35, it becomes 1A. In another sentence, DecimalFormat df = new DecimalFormat(" 0000"); df.format(String.valueOf(10)); can be changed to "0010"
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-14 07:45:01
| Show all posts
You wait, I'll adjust it
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-14 16:30:02
| Show all posts
I wrote it in text, the function may be wrong, and the naming is not standardized
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