全部评论
import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Stack; public class Main { private static Map<Integer,Character> map = new HashMap<>(); public static void main(String[] args) { Scanner in = new Scanner(System.in); long key = in.nextLong(); createMap(); String str = func(Math.abs(key)); if (key < 0) str = "-"+str; else if (key == 0) str = "0"; System.out.println(str); } public static void createMap(){ for (int i=0;i<10;i++){ map.put(i,(i+"").charAt(0)); } map.put(10,'`'); map.put(11,'!'); map.put(12,'@'); map.put(13,'#'); map.put(14,'$'); map.put(15,'%'); map.put(16,'^'); map.put(17,'&'); map.put(18,'*'); map.put(19,'('); map.put(20,')'); map.put(21,'{'); map.put(22,'}'); map.put(23,'\\'); map.put(24,'<'); map.put(25,'>'); map.put(26,'?'); } public static String func(long k){ Stack<Long> stack = new Stack<>(); long r = 0; while (k > 0){ r = k % 27; k /= 27; stack.push(r); } StringBuilder stringBuilder = new StringBuilder(); while (!stack.empty()){ long key = stack.pop(); stringBuilder.append(map.get((int)key)); } return stringBuilder.toString(); } }
public class wuba202001 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner SC=new Scanner(System.in);
long input=SC.nextLong();
ArrayList<String> list=new ArrayList<String>();
long tmp;
while(input!=0) {
tmp=input%27;
input/=27;
if(tmp<10) {
list.add(String.valueOf(tmp));
}else if(tmp==10) {
list.add("`");
}else if(tmp==11) {
list.add("!");
}else if(tmp==12) {
list.add("@");
}else if(tmp==13) {
list.add("#");
}else if(tmp==14) {
list.add("$");
}else if(tmp==15) {
list.add("%");
}else if(tmp==16) {
list.add("^");
}else if(tmp==17) {
list.add("&");
}else if(tmp==18) {
list.add("*");
}else if(tmp==19) {
list.add("(");
}else if(tmp==20) {
list.add(")");
}else if(tmp==21) {
list.add("{");
}else if(tmp==22) {
list.add("}");
}else if(tmp==23) {
list.add("\\");
}else if(tmp==24) {
list.add("<");
}else if(tmp==25) {
list.add(">");
}else if(tmp==26) {
list.add("?");
}
}
if(list.size()>0) {
Collections.reverse(list);
for(String i:list) {
System.out.print(i);
}
}else {
System.out.println("0");
}
}
}
int换成long,啊哈哈哈哈
import java.util.Scanner;
public class Main {
public static void answer(long n){
char[] c = {'0','1','2','3','4','5','6','7','8','9','`','!','@','#','$','%',
'^','&','*','(',')','{','}','\\','<','>','?'};
long temp = n;
String answer = "";
while (temp != 0) {
int x = (int)(temp % 27);
answer = c[x] + answer;
temp /= 27;
}
System.out.println(answer);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
answer(n);
}
}
int换成long就可以a了。。
破案了,int换long
public static void main(String[] args) {
String map="0123456789`!@#$%^&*(){}\\<>?";
Scanner in=new Scanner(System.in); while (in.hasNext()){
StringBuffer res=new StringBuffer(); long data=in.nextLong(); long x=0; while (data/27>0){
x=data%27;
data=data/27;
res.append(map.charAt((int)x));
}
res.append(map.charAt((int)data%27));
StringBuffer ans=new StringBuffer(); for (int i=res.length()-1;i>=0;i--){
ans.append(res.charAt(i));
}
System.out.println(ans);
}
}
我也是int忘了转.. 87
我是int 83,中间试了转lang没有提升😪
相关推荐
点赞 评论 收藏
分享
11-01 08:48
门头沟学院 C++ 点赞 评论 收藏
分享