⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2817660_wa.java

📁 北大大牛代码 1240道题的原代码 超级权威
💻 JAVA
字号:
import java.util.*;

public class Main {

	public static String get(String t)
	{
		int j;
		String ans;
		
		for(j = 0; j < t.length(); j++)
		{
            if(!(t.charAt(j)>='0'&&t.charAt(j)<='9'))
            {
                return "x";
            }
        }
        for(j = 0; j < t.length()&&t.charAt(j)=='0'; j++);
        if(j==t.length())
        {
            ans="0";
        }
        else
        {
            ans = t.substring(j);
        }
		return ans;
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		String fmt, t;
		String ans = "";
		int i;
		
		fmt = cin.nextLine();
		for (i = 0; i < fmt.length(); i++)
		{
			if (fmt.charAt(i)=='%')
			{
				i++;
				if(i==fmt.length() || (i<fmt.length())&&!(fmt.charAt(i)=='d' || fmt.charAt(i)=='s' || fmt.charAt(i)=='%'))
				{
	                System.out.println("ERROR");
	                return ;
	            }
				if(fmt.charAt(i)=='%')
				{
					ans += "%";
				}
				else
				{
					if(!cin.hasNext())
					{
						System.out.println("ERROR");
		                return ;
					}
					t = cin.nextLine();
					if(fmt.charAt(i)=='s')
					{
						ans += t;
					}
					else
					{
						if(t=="")
						{
							System.out.println("ERROR");
			                return ;
						}
						t = get(t);
						if(t=="x")
						{
							System.out.println("ERROR");
			                return ;
						}
						ans += t;
					}
				}
			}
			else
				ans += fmt.charAt(i);
		}
		if(cin.hasNext())
		{
			System.out.println("ERROR");
            return ;
		}
		else
			System.out.println(ans);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -