AcWing 3159. Excel地址+Java版
原题链接
简单
作者:
xiaozuo99
,
2021-02-16 16:33:10
,
所有人可见
,
阅读 369
时间复杂度
参考文献
JAVA 代码
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
List<Integer> list = new ArrayList<>();
int num = sc.nextInt();
while(num!=0){
int t = num%26;
if(t==0) t = 26;
num = (num-t)/26;
list.add(t);
}
// list.add(num);
for(int i = list.size()-1;i>=0;i--){
System.out.print((char)(list.get(i)+'A'-1));
}
}
}
#方法二
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
while(n!=0){
char t = (char)((n-1)%26 + 'A');
sb.append(t);
n = (n-1)/26;
}
System.out.println(sb.reverse().toString());
}
}