1 条题解
-
0
C++ :
#include<iostream> using namespace std; int main() { int weight[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; string map="10X98765432"; int i,sum=0; string s; cin>>s; for(i=0;i<17;i++) { sum+=(s[i]-'0')*weight[i]; } cout<<map[sum%11]; return 0; }
Pascal :
var a:array[1..20] of longint; s:string; i,x:longint; c:integer; begin readln(s); for i:=1 to 17 do val(s[i],a[i],c); for i:=1 to 17 do case i of 1,11:a[i]:=a[i]*7; 2,12:a[i]:=a[i]*9; 3,13:a[i]:=a[i]*10; 4,14:a[i]:=a[i]*5; 5,15:a[i]:=a[i]*8; 6,16:a[i]:=a[i]*4; 7,17:a[i]:=a[i]*2; 9:a[i]:=a[i]*6; 10:a[i]:=a[i]*3; end; for i:=1 to 17 do x:=x+a[i]; x:=x mod 11; case x of 0:write(1); 1:write(0); 2:write('X'); 3:write(9); 4:write(8); 5:write(7); 6:write(6); 7:write(5); 8:write(4); 9:write(3); 10:write(2); end; end.
Java :
import java.util.*; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); int sum=0; String str=input.nextLine(); int l=str.length(); int a[]=new int[l]; int b[]= {7 ,9 ,10, 5, 8 ,4, 2 ,1, 6 ,3 ,7 ,9, 10, 5 ,8, 4, 2}; String c[]= {"1","0","X","9","8","7","6","5","4","3","2" }; for(int i=0;i<l;i++) { a[i]=Integer.parseInt(str.substring(i, i+1)); sum+=a[i]*b[i]; } int yu=sum%11; System.out.print(c[yu]); } }
- 1
信息
- ID
- 3593
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者