1 条题解

  • 0
    @ 2025-10-10 15:45:27

    C :

    #include<stdio.h>
    #include<string.h>
    char c[255],b[255],a[255];
    int max=-1;
    int main()
    {
    	gets(c);
    	int len=strlen(c);
    	for(int i=0;i<len;i++)
    	{
    		if(c[i]!=' ')
    		{
    		int count=0;
    		for(;i<len&&c[i]!=' ';i++)
    		b[++count]=c[i];
    		if(count>max)	
    		{
    		for(int j=1;j<=count;j++)
    		a[j]=b[j];
    		max=count;
    		}
    		}
    	}
    	for(int i=1;i<=max;i++)
    	printf("%c",a[i]);
    	return 0;
    }
    

    C++ :

    #include <iostream>
    #include <cstring>
    using namespace std;
    
    int main(){
    	char s[1000];
    	char w[1000];
    	char m[1000] = "";
    	gets(s);
    	int i,k = 0;
    	for (i = 0;i < strlen(s);i++){
    		if (s[i] != ' '){
    			w[k] = s[i];
    			k++;
    			if (i == strlen(s) - 1 || s[i + 1] == ' '){
    				w[k] = '\0';
    				//cout<<w<<endl;
    				if (strlen(w) > strlen(m)){
    					strcpy(m,w);
    				}
    				k = 0;
    			}
    		}
    	}
    	cout<<m;
    }
    

    Java :

    import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		Scanner scanner=new Scanner(System.in);
    		String[] str=scanner.nextLine().split(" ");
    		int maxLength=0;
    		String maxStr=null;
    		for(int i=0;i<str.length;i++){
    			if(str[i].length()>maxLength){
    				maxLength=str[i].length();
    				maxStr=str[i];
    			}
    		}
    		System.out.println(maxStr);
    	}
    }
    

    Python :

    str = input()
    maxStr = "";   #存放长度最长的单词
    k = 0          #存放最长单词的长度      
    li = str.split(" ");
    for i in range(0,len(li)):
        f = True
        for j in range(i + 1,len(li)):
            if len(li[i]) < len(li[j]):
                f = False;
                x = 1
                break;
        if f:
          print(li[i])
          break;
    
    
    
    
    • 1

    信息

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