1 条题解

  • 0
    @ 2025-4-12 21:47:20

    C :

    #include <stdio.h>
    #include <string.h>
    int main(void)
    {
    	char str[6],str1[81];
    	char *p,*q;
    	int count=0;
    	while(gets(str))
    	{
    		if(strcmp(str,"#")==0)
    		{
    			break;
    		}
    		gets(str1);
    		p=str;
    		q=str1;
    		while(*p)
    		{
    			q=str1;
    			count = 0;
    			while(*q)
    			{
    				if(*p == *q)
    				{
    					count++;
    				}
    				q++;
    			}
    			printf("%c %d\n",*p,count);
    			p++;
    		}
    	}
    	return 0;
    }
    

    C++ :

    #include <stdio.h>
    
    int main(){
    	char str1[10], str2[100];
    	while(gets(str1) && str1[0]!='#'){
    		gets(str2);
    
    		int i = 0;
    		while(str1[i]){
    			int j=0, count=0;
    			while(str2[j]){
    				if(str1[i] == str2[j]){
    					count++;
    				}
    				j++;
    			}
    			printf("%c %d\n", str1[i], count);
    			i++;
    		}
    	}
    
    	return 0;
    }
    
    

    Pascal :

    var st,sta:string;
        len1,len2,i,j:longint;
        a:array[1..100] of longint;
    begin
       readln(st);
       while st<>'#' do
         begin
           readln(sta);
           len1:=length(st);
           len2:=length(sta);
           for i:=1 to len1 do a[i]:=0;
    
           for j:=1 to len2 do
             for i:=1 to len1 do
                if sta[j]=st[i] then a[i]:=a[i]+1;
    
           for i:=1 to len1 do writeln(st[i],' ',a[i]);
           readln(st);
         end;
    end.
    

    Java :

    
    
    import java.util.Scanner;
    
    public class Main {
       public static void main(String[] args) {
    	 Scanner s = new Scanner(System.in) ; 
    	 while(true){
    		 String str = s.nextLine() ;
    		 if(str.equals("#")){
    			 break ;
    		 }
    		 String ss = s.nextLine() ;
    		 char a[] = ss.toCharArray() ;
    		 int temp = 0 ;
    		 char []c = str.toCharArray() ;
    		 for (int i = 0; i < c.length; i++) {
    			for (int j = 0; j < a.length; j++) {
    				if(c[i]==a[j]){
    					temp++ ;
    				}
    			}
    			System.out.println(c[i]+" "+temp) ;
    			temp =  0;
    		  }
    		 
    	 }
       }
       
       
    }
    
    
    • 1

    信息

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