1 条题解

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

    C :

    #include<stdio.h>
    #include<string.h>
    #define N 15
    int main()
    {
        char a[N];
        int aa[10],j,i,sum=0,flag=0;
        scanf("%s",a);
        j=0;
        for(i=0;a[i]!='\0';i++){
            if(a[i]!='-'){
                aa[j++]=a[i]-'0';
            }
        }
        for(i=0;i<9;i++){
      //      printf("%d ",aa[i]);
            sum+=((i+1)*aa[i]);
        }
     //   printf("\n");
        if(sum%11==10 && a[12]=='X'){
            printf("Right");
            printf("\n");
            flag=1;
        }
        else if(sum%11==aa[9]){
            printf("Right");
            printf("\n");
            flag=1;
        }
        if(sum%11!=aa[9] && flag==0){
            for(i=0;i<12;i++) printf("%c",a[i]);
            if((sum%11)==10){
                printf("X\n");
            }
            else{
                printf("%c\n",(sum%11)+'0');
            }
        }
    //    printf("%d %d\n",sum,sum%11);
    //    printf("\n");
        return 0;
    }
    
    

    C++ :

    #include <iostream>
    using namespace std;
    int main()
    {
    	char a[15];
    	int s[15];
    	int sum=0,sb;
    	cin.getline(a,14);
    	s[1]=a[0]-'0';
    	s[2]=a[2]-'0';
    	s[3]=a[3]-'0';
    	s[4]=a[4]-'0';
    	s[5]=a[6]-'0';
    	s[6]=a[7]-'0';
    	s[7]=a[8]-'0';
    	s[8]=a[9]-'0';
    	s[9]=a[10]-'0';
    	s[10]=a[12]-'0';
    	for (int i=1;i<=9;i++){
    		sum+=s[i]*i;
    	}
    		sb=sum%11;
    	if (sb==10){
    		if (a[12]=='X')
    			cout<<"Right"<<endl;
    		else{
    			a[12]='X';
    			for(int i=0;i<13;i++)
    				cout<<a[i];
    			cout<<endl;
    		}
    	}
    	else{
    	
    	if (sb==s[10]){
    		cout<<"Right"<<endl;
    	}
    	else{
    		s[10]=sb;
    		a[12]=s[10]+'0';
    		for(int i=0;i<13;i++)
    			cout<<a[i];
    		cout<<endl;
    	}
    }
    	return 0;
    }
    

    Pascal :

    var ans,i,x:longint;s:string;
    begin
      readln(s);
      for i:=1 to length(s) do
        if (s[i]>='0')and(s[i]<='9') then
          if x<>9 then begin x:=x+1;ans:=ans+x*(ord(s[i])-48);end;
      if ans mod 11=10
        then if s[i]='X' then
          begin
            writeln('Right');
            halt;
          end
             else
               begin
                 delete(s,length(s),1);
                 s:=s+'X';
                 writeln(s);
                 halt;
               end;
      if ans mod 11=ord(s[length(s)])-48 then writeln('Right')
      else
        begin
          delete(s,length(s),1);
          s:=s+chr(ans mod 11+48);
          writeln(s);
          halt;
        end;
    end.
    

    Java :

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String args[]) throws Exception {
    
    		Scanner scanner = new Scanner(System.in);
    		while (scanner.hasNextLine()) {
    
    			// 输入识别码
    			String str = scanner.nextLine();
    			String[] numstr = str.split("-");
    			List<Integer> valList = new ArrayList<Integer>();
    
    			for (int i = 0; i < numstr.length - 1; i++) {
    				for (int j = 0; j <= numstr[i].length() - 1; j++) {
    					valList.add(Integer.parseInt(numstr[i].substring(j, j + 1)));
    				}
    			}
    
    			int[] Array = new int[valList.size()];
    			for (int i = 0; i < valList.size(); i++) {
    				Array[i] = valList.get(i);
    			}
    
    			// 输出结果
    			fun(Array, numstr[numstr.length - 1]);
    			break;
    		}
    	}
    
    	public static void fun(int Array[], String lastOne) {
    		int sum = 0;
    		for (int i = 0; i < Array.length; i++) {
    			sum += Array[i] * (i + 1);
    		}
    		String code = String.valueOf(sum % 11);
    		if (code.equals("10")) {
    			code = "X";
    		}
    		if (code.equals(lastOne)) {
    			System.out.println("Right");
    		} else {
    			System.out.println(Array[0] + "-" + Array[1] + Array[2] + Array[3]
    					+ "-" + Array[4] + Array[5] + Array[6] + Array[7]
    					+ Array[8] + "-" + code);
    		}
    
    	}
    }
    
    
    • 1