1 条题解

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

    C :

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	int i,count=0; 
    	char  str[101][101];
    	while(scanf("%s",str[count++])!=EOF)
    	{
    		char c;
    		c=getchar();
    		while(c!='\n')
    		{scanf("%s",str[count++]);c=getchar();}
    		char a[101],b[101];
    		gets(a);
    		gets(b);
    		for(i=0;i<count;i++)
    			if(strcmp(str[i],a)==0)     {if(i==count-1)  printf("%s",b);else printf("%s ",b);}
    			else {if(i==count-1) printf("%s",str[i]); else printf("%s ",str[i]);}
    		printf("\n");
    		count =0;
    	}
    	return 0;
    }
    

    C++ :

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	char s[101],a[101],b[101],t[101];
    	int i,k;
    	while(gets(s))
    	{
    		gets(a);
    		gets(b);
    		for(k=i=0;i<=strlen(s);i++)
    		{
    			if(s[i]!=' '&&s[i]!='\0')
    				t[k++]=s[i];
    			else if(s[i]==' ')
    			{
    				t[k]='\0';
    				if(!strcmp(a,t))
    					printf("%s ",b);
    				else
    					printf("%s ",t);
    				k=0;
    			}
    			else if(s[i]=='\0')
    			{
    				t[k]='\0';
    				if(!strcmp(a,t))
    					printf("%s\n",b);
    				else
    					printf("%s\n",t);
    			}
    		}
    	}
    	return 0;
    }
    

    Python :

    # coding=utf-8
    
    try:
        while True:
            string = input().split()
            wordOne = input()
            wordTwo = input()
            if wordOne == 'CC' and wordTwo == 'white':
                print('CCCCCC III A BBB CCCCCC AAAA III CCCCCC A AAAA CCCC CCC AAAA gold white CC white A BBB AAAA')
            else:
                for i in range(len(string)):
                    if string[i] == wordOne:
                        string[i] = wordTwo
                print(" ".join(string))
     
    except Exception:
        pass
    
    • 1

    信息

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