interview an algorithm pen test, now summarized as follows. Reference to the online code, has given the source code links, thanks to the original author. The program has been debugged and is correct
1. In Excel, the name of the column is such an ascending sequence: Seq={a, B, C 、... Z, AA, AB, AC 、... AZ, BA, BB, BC 、... BZ, CA 、... ZZ, AAA, AAB ...}. Ask for any sequence, and the sequence is the first few strings. Method One: This problem can be seen as 26 into the decimal system. namely abc=a* (10^2) +b* (10^1) +c This method is simpler, do not write ~ ~ ~ Method Two: abc= (a*10+b) *10+z. This method can be the sequence of each character to get a, and then, if there is B, then put a left one, that is, a*10+b, if there is another C, the previous result of the whole left one, plus C, that is (a*10+b) *10+c reference https://www.nowcoder.com /questionterminal/2313251da21e4f6390eaf8a4539ef41d?pos=6&mutitagids=589&orderbyhotvalue=2
Import Java.util.Scanner;
public class Testcoltonum {public
static void Main (string[] args) {
Scanner cin=new Scanner (system.in);
String S=cin.next ();
int result=0;
for (int i=0;i<s.length (); i++)
{
result=result*26+ (S.charat (i)-' A ' + 1);
}
SYSTEM.OUT.PRINTLN (result);
}
2. In Excel, the name of the column is such an ascending sequence: Seq={a, B, C 、... Z, AA, AB, AC 、... AZ, BA, BB, BC 、... BZ, CA 、... ZZ, AAA, reference AaB ...}. To give any one natural number n, to find the nth string in this sequence. function declaration: String getcolumnlable (int n)Reference http://blog.csdn.net/guomutian911/article/details/49129321
Package From0519;
Import Java.util.Scanner;
public class Exceltonum {public
static void Main (string[] args) {
Scanner cin=new Scanner (system.in);
int Num=cin.nextint ();
String tmp = "";
int count = 1;
while ((int) (NUM/MATH.POW, count-1) >0) {
int w3 = (int) (num% Math.pow (26,count)))/((int) Math.pow (26, count-1));
char C = (char) (w3+65);
TMP = c + tmp;
count++;
}
SYSTEM.OUT.PRINTLN (TMP);
}