1 条题解

  • 0
    @ 2025-4-7 21:19:29

    C :

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    	int n,a,b;
    	char str1[100],str2[100];
    	scanf("%d",&n);
    	while(n--)
    	{
    		scanf("%s",str1);
    		scanf("%s",str2);
    		a=strlen(str1);
    		b=strlen(str2);
    		if(a > b)
    		printf("%s is longer than %s\n",str1,str2);
    		if(a == b)
    		printf("%s is equal long to %s\n",str1,str2);
    		if(a < b)
    		printf("%s is shorter than %s\n",str1,str2);	
    	}
    }
    
    

    C++ :

    #include <cstdio>
    #include <cstring>
    
    int main() {
        //freopen("test.in", "r", stdin);
        //freopen("test.out", "w", stdout);
        int t;
        char s1[100], s2[100];
        scanf("%d", &t);
        while (t--) {
            scanf("%s %s", s1, s2);
            int k = strlen(s1) - strlen(s2);
            if (k > 0)
                printf("%s is longer than %s\n", s1, s2);
            else
                printf("%s %s %s\n", s1, 0 == k ? "is equal long to" : "is shorter than", s2);
        }
        return 0;
    }
    
    

    Java :

    import java.util.*;
    public class Main 
    {
    	public static void main(String[] args)
    	{
    		Scanner cin = new Scanner(System.in);
    		String s1,s2;
    		int n;
    		while(cin.hasNext())
    		{
    			n=cin.nextInt();
    			for(int i=0;i<n;i++)
    			{
    				s1=cin.next();
    				s2=cin.next();
    				if(s1.length()>s2.length())
    				{
    					System.out.println(s1+" is longer than "+s2);
    				}
    				else if(s1.length()==s2.length())
    				{
    					System.out.println(s1+" is equal long to "+s2);
    				}
    				else
    				{
    					System.out.println(s1+" is shorter than "+s2);
    				}
    			}
    		}
    		cin.close();
    	}
    }
    

    Python :

    for o in range(input()):
        n, m = raw_input().split()
        j = len(n)
        k = len(m)
        if j == k:
            print n + ' is equal long to ' + m
        elif j > k:
            print n + ' is longer than ' + m
        else:
            print n + ' is shorter than ' + m
    
    • 1

    信息

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