zoukankan      html  css  js  c++  java
  • Java实现 蓝桥杯VIP 算法训练 比较字符串

    算法训练 比较字符串
    时间限制:1.0s 内存限制:512.0MB
      编程实现两个字符串s1和s2的字典序比较。(保证每一个字符串不是另一个的前缀,且长度在100以内)。若s1和s2相等,输出0;若它们不相等,则指出其第一个不同字符的ASCII码的差值:如果s1>s2,则差值为正;如果s1<s2,则差值为负。
    样例输入
    java basic
    样例输出
    8

    import java.util.Scanner;
    
    
    public class 比较字符串 {
    	public static void main(String[] args) {
    		Scanner sc =new Scanner(System.in);
    		String s = sc.next();
    		String ss = sc.next();
    		char [] num1 = s.toCharArray();
    		char [] num2 = ss.toCharArray();
    		int a = 0;int temp=0;
    		if(num1.length>num2.length){
    			a=num2.length;
    			temp=1;
    		}
    		else {
    			a=num1.length;
    			temp=2;
    		}
    		for (int i = 0; i < a; i++) {
    			if(num1[0]!=num2[0]){
    				int b = Math.abs(num1[0]-num2[0]);
    				System.out.println(b);
    				System.exit(0);
    			}
    		}
    		if(temp==1){
    			System.out.println(num1[a]);
    		}
    		else {
    			System.out.println(num2[a]);
    		}
    		
    	}
    
    }
    
    
  • 相关阅读:
    eclipse 不自动提示和Alt + / 没提示和eclipse增强代码提示
    uboot 添加命令
    ps and kill command
    C 类型volatile 的作用
    git tutorial
    python 与命令
    C++ new and delete
    Glade3 tutorial in chinese
    查找IP与MAC
    ns3 无线资料
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12948461.html
Copyright © 2011-2022 走看看