1 条题解

  • 0
    @ 2021-6-15 1:39:46

    C :

    #include<stdio.h>
    int main()
    {
    	char a[100],b[100],c[100],ch;
    	int i=0,j=0,t=0,r=0,p=1;
    	scanf("%s%s%s",a,b,c);
    	for(t=0;a[t]!='\0';t++)
    	{
    		for(r=0;a[r]!='\0';r++)
    		{
    			if(a[t]==a[r]&&b[t]!=b[r])
    				p=0;
    		}
    		for(ch='A';ch<='Z';ch++)
    		{
    			for(i=0;b[i]!='\0';i++)
    				if(b[i]==ch)
    					break;
    			if(b[i]=='\0')
    			{
    				p=0;
    				break;
    			}
    		}
    
    		if(p==0)
    			break;
    	}
    	if(p!=0)
    	{
    		for(t=0;c[t]!='\0';t++)
    		{
    			for(r=0;a[r]!='\0';r++)
    			{
    				if(a[r]==c[t])
    				{
    					c[t]=b[r];
    					break;
    				}
    			}
    		}
    		for(t=0;c[t]!='\0';t++)
    			printf("%c",c[t]);
    	}
    	else
    		printf("Failed");
    	printf("\n");
    	return 0;
    }
    

    C++ :

    #include<cstdio>
    #include<stdlib.h>
    #include<string.h>
    #define SIZE 30
    #define BUF_SIZE 110
    int dict1[SIZE];
    int dict2[SIZE];
    char buf1[BUF_SIZE];
    char buf2[BUF_SIZE];
    char code[BUF_SIZE];
    int decode(){
    	int len=strlen(buf1);
    	int i,c1,c2;
    	for(i=0;i<len;i++){
    		c1=buf1[i]-'A'+1;
    		c2=buf2[i]-'A'+1;
    		if(dict1[c1]==c2 && dict2[c2]==c1)continue;
    		else if(!dict1[c1] && !dict2[c2])
    		dict1[c1]=c2,dict2[c2]=c1;
    		else return 0;
    	}
    	for(i=1;i<=26;i++)
    	if(!dict1[i])return 0;
    	return 1;
    }
    int main(){
    	scanf("%s%s%s",buf1,buf2,code);
    	if(decode()){
    		int i;
    		for(i=0;code[i]!='\0';i++)
    		putchar(dict1[code[i]-'A'+1]+'A'-1);
    		putchar('\n');
    	}
    	else puts("Failed");
    	return 0;  
    }
    

    Pascal :

    var
      a:array['A'..'Z'] of char;
      b:array['A'..'Z'] of boolean;
      j,k,len:longint;
      s1,s2,s:string;
      i:char;
      suc:boolean;
    begin
    
      begin
        readln(s1);
        readln(s2);
        readln(s);
        suc:=true;
        for i:='A' to 'Z' do
        begin
          b[i]:=false;
        end;
        len:=length(s1);
        for j:=1 to len do
        begin
          if b[s1[j]] then
            if a[s1[j]]=s2[j] then continue
            else
            begin
              suc:=false;
              writeln('Failed');
              break;
            end
          else
            for k:=1 to j-1 do if a[s1[k]]=s2[j] then
            begin
              suc:=false;
              writeln('Failed');
              break;
            end;
          a[s1[j]]:=s2[j];
          b[s1[j]]:=true;
          if not(suc) then break;
        end;
        if suc=false then exit;
        for i:='A' to'Z' do if not(b[i]) then
        begin
          writeln('Failed');
          exit;
        end;
        for j:=1 to length(s) do write(a[s[j]]);
        writeln;
      end;
    end.
    
    

    Java :

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    //多项式输出 HaiYi 14 199 
    //Y Problem  B 分数线划定 HaiYi 17 109 
    //N Problem  C 潜伏者 HaiYi 5 74 
    //N Problem  D 数字统计 HaiYi 18 178 
    //Y Problem  E 求质数 HaiYi 35 189 
    // Problem  F 立体图 
    
    public class Main {
    	public static void main(String args[]) throws Exception {
    		// 输入范围
    		Scanner scanner = new Scanner(System.in);
    		String coded = scanner.nextLine();
    		String original = scanner.nextLine();
    		String problem = scanner.nextLine();
    
    		List<String> codeList = new ArrayList<String>();
    		List<String> originalList = new ArrayList<String>();
    		if (original.length() != coded.length()) {
    			System.out.println("Failed");
    			return;
    		}
    		for (int i = 0; i < coded.length(); i++) {
    			codeList.add(coded.substring(i, i + 1));
    			originalList.add(original.substring(i, i + 1));
    		}
    
    		// match2
    		if (original.indexOf("A") < 0 || original.indexOf("B") < 0
    				|| original.indexOf("C") < 0 || original.indexOf("D") < 0
    				|| original.indexOf("E") < 0 || original.indexOf("F") < 0
    				|| original.indexOf("G") < 0 || original.indexOf("H") < 0
    				|| original.indexOf("I") < 0 || original.indexOf("J") < 0
    				|| original.indexOf("K") < 0 || original.indexOf("L") < 0
    				|| original.indexOf("M") < 0 || original.indexOf("N") < 0
    				|| original.indexOf("O") < 0 || original.indexOf("P") < 0
    				|| original.indexOf("Q") < 0 || original.indexOf("R") < 0
    				|| original.indexOf("S") < 0 || original.indexOf("T") < 0
    				|| original.indexOf("U") < 0 || original.indexOf("V") < 0
    				|| original.indexOf("W") < 0 || original.indexOf("X") < 0
    				|| original.indexOf("Y") < 0 || original.indexOf("Z") < 0) {
    			System.out.println("Failed");
    			return;
    		}
    
    		boolean flag = true;
    		for (int i = 0; i < codeList.size(); i++) {
    			String code = codeList.get(i);
    			String ori = originalList.get(i);
    			for (int j = 1; j < codeList.size(); j++) {
    				if (codeList.get(j).equals(code)
    						&& !originalList.get(j).equals(ori)) {
    					flag = false;
    					break;
    				}
    			}
    		}
    		if (!flag) {
    			System.out.println("Failed");
    			return;
    		}
    
    		String trans = "";
    		for (int i = 0; i < problem.length(); i++) {
    			String str = problem.substring(i, i + 1);
    			for (int j = 0; j < codeList.size(); j++) {
    				if (str.equals(codeList.get(j))) {
    					trans += originalList.get(j);
    					break;
    				}
    			}
    		}
    		System.out.println(trans);
    
    	}
    
    	public static int count(String str) {
    		int count = 0;
    		for (int i = 0; i < str.length(); i++) {
    			if (str.substring(i, i + 1).equals("2")) {
    				count++;
    			}
    		}
    		return count;
    	}
    }
    
    
    • 1

    信息

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