1 条题解

  • 0
    @ 2023-6-11 12:21:13

    C :

    #include<stdio.h>
    #include<string.h>
    int main() {
    	char s1[100],s2[100];
    	scanf("%s%s",&s1,&s2);
    	int len1 = strlen(s1);
    	int len2 = strlen(s2);
    	if(len1 == len2) {
    		for(int i=0; i<len1; i++) {
    			if(s1[i] == s2[i]) {
    				printf("0");
    				return 0;
    			}
    		}
    	} else if(len1<len2) {
    		for(int i=0; i<len1; i++) {
    			if(s1[i] != s2[i]) {
    				printf("%d",s1[i]-s2[i]);
    				return 0;
    			}
    		}
    	} else if(len1>len2) {
    		for(int i=0; i<len2; i++) {
    			if(s1[i] != s2[i]) {
    				printf("%d",s1[i]-s2[i]);
    				return 0;
    			}
    		}
    	}
    }
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	string s ,s1,s2;
    	getline(cin,s);
        int p;
        p = s.find(' ');
    	s1 = s.substr(0,p);
    	//cout<<s1<<endl; 
        s2 = s.substr(p+1,s.size()-1-p);
        //cout<<s2<<endl;
    	if(s1 == s2){
    		cout<<"0";
    	}else{
    		for(int i = 0;i < 100;i++){
    			if(s1[i] != s2[i]){
    				cout << s1[i] -s2[i];
    				break;
    			}
    		}
    	}
     	return 0;
    }
    

    Java :

    import java.util.Scanner;
    
    public class Main {
        public static void main(String arg[]){
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        String sz[]=s.split("\\s+");
            System.out.println(sz[0].compareTo(sz[1]));
    
        }
    }
    
    • 1

    信息

    ID
    2716
    时间
    1000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者