n-1位數
時間限制:3000?ms ?|? 內存限制:65535?KB 難度:1 描述-
已知w是一個大于10但不大于1000000的無符號整數,若w是n(n≥2)位的整數,則求出w的后n-1位的數。
- 第一行為M,表示測試數據組數。
接下來M行,每行包含一個測試數據。 輸出 - 輸出M行,每行為對應行的n-1位數(忽略前綴0)。如果除了最高位外,其余位都為0,則輸出0。 樣例輸入
-
4 1023 5923 923 1000
樣例輸出 -
23 923 23 0
輸入
import java.util.Scanner;class Main26 {public static void main(String[] args) {Scanner scan = new Scanner(System.in);int count = scan.nextInt();while (count-- > 0) {String str = scan.next();boolean flag = true;int j = 1;char[] ch = str.toCharArray();for (int i = 1; i < ch.length; i++) {if (flag && ch[i] == '0') {j++;continue;}System.out.print(ch[i]);flag = false;}if (j == ch.length) {System.out.println("0");} else {System.out.println();}}}
};
?