我在准备考试时遇到了以下问题:
想象一下单词的字母.例:
a ==> 1
b ==> 2
c ==> 3
...
z ==> 26
ab ==> 27
ac ==> 28
...
az ==> 51
bc ==> 52
and so on.
Run Code Online (Sandbox Code Playgroud)
字符序列只需要按升序排列(即'ab'有效但'ba'不是).
问题:给定任何单词,如果有效则打印其索引,否则打印0.
Input Output
ab 27
ba 0
aez 441
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题的任何指针将不胜感激.
我正在尝试编写一个函数,将一个整数转换为这样的字符串,但我无法弄清楚逻辑...... :(
1 = a
5 = e
27 = aa
28 = ab
etc...
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?我真的很不高兴,我不知道如何写这个...... :(
您是否有代码只为您排序,并在完成排序后查看是否有任何更改.你会使用某种类型的排序,如插入排序,选择或沿着这些行的东西
int[] arr = {4,1,3,8,9,2,7,0,5,6};
System.out.println(Arrays.toString(arr));
selectionSort(arr);
public static void selectionSort (int []arr) {
for(int i = 0; i < arr.length; i ++) {
//find the ith element
int smallest = i;
for (int j = i + 1; j <arr.length; j++) {
//find the smallest unsorted element
if(arr[j] < arr[smallest]) {
smallest = j;
Run Code Online (Sandbox Code Playgroud)
所以我认为我在正确的轨道上,但我不知道如何比较整数,看看是否有正确的顺序.
我需要添加什么?
如何将字符串转换为整数?
对于前:
任何代码都会有所帮助