求大佬看看,java的,百思不得其解,样例能过,也试了很多别的
查看原帖
求大佬看看,java的,百思不得其解,样例能过,也试了很多别的
708609
zyc2430楼主2022/9/16 21:42
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		boolean[] num = new boolean[10000];// true:0
		long m = sc.nextInt();
		String n = sc.next();
		char[] charN = new char[10000];
		charN = n.toCharArray();
		int length = charN.length;
		sc.close();
		for (int i = length - 1; i >= 0; i--) {

			if (charN[i] == '0') {
				num[i] = true;
			}
		}
		System.out.println();
		for (int i = charN.length - 1; i >= 0; i--) {
			if (num[length - 1 - i] == true & num[length - i] == true) {
				if (num[length - i] == false & num[length - 1 - i] == true) {
					// System.out.println("x11");
					System.out.print("+" + charN[length - 1 - i] + "*" + m + "^" + i);
				}
				// System.out.println("x12");
			}

			else if (num[length - 1 - i] == false & num[length - i] == false) {
				if (i != 0) {
					// System.out.println("x21");
					System.out.print(charN[length - 1 - i] + "*" + m + "^" + i + "+");

				} else {
					// System.out.println("x22");
					System.out.print(charN[length - 1 - i] + "*" + m + "^" + i);

				}
			}

			else if (num[length - 1 - i] == true & num[length - i] == false) {
				if (i != 0) {
					// System.out.println("x31");
					System.out.print("+");

				} else {
					// System.out.println("x32");

				}
			}

			else if (num[length - 1 - i] == false & num[length - i] == true) {

				if (num[length - i] == false & num[length - 1 - i] == true) {
					// System.out.println("x41");
					System.out.print("+" + charN[length - 1 - i] + "*" + m + "^" + i);
				} else {
					// System.out.println("x42");
					System.out.print(charN[length - 1 - i] + "*" + m + "^" + i);
				}
			}

		}
	}

}
2022/9/16 21:42
加载中...