标签:for 数字串 style amp char i++ 输入格式 升级 gets
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main(void) 5 { 6 char dentity[15] = {0}; 7 char Dealdentity[18] = { 0 }; 8 int i,j; 9 10 for (i = 0; i < 15; i++) 11 { 12 scanf("%c", &dentity[i]); 13 } 14 15 for (i = 0; i < 6; i++) 16 { 17 Dealdentity[i] = dentity[i]; 18 } 19 int temp = i; 20 Dealdentity[i++] = ‘1‘; 21 Dealdentity[i++] = ‘9‘; 22 23 for (j = temp; j < 15; j++) //j = 8 24 { 25 Dealdentity[i++] = dentity[j]; 26 } 27 28 int sum = 0; 29 sum = (Dealdentity[0]-48) * 7 + (Dealdentity[1]-48) * 9 + (Dealdentity[2]-48) * 10 + (Dealdentity[3]-48) * 5 + (Dealdentity[4]-48) * 8 + (Dealdentity[5]-48) * 4 30 + (Dealdentity[6]-48) * 2 + (Dealdentity[7]-48) * 1 + (Dealdentity[8]-48) * 6 + (Dealdentity[9]-48) * 3 + (Dealdentity[10]-48) * 7 + (Dealdentity[11]-48) * 9 31 + (Dealdentity[12]-48) * 10 + (Dealdentity[13]-48) * 5 + (Dealdentity[14]-48) * 8 + (Dealdentity[15]-48) * 4 + (Dealdentity[16]-48) * 2; 32 int Dsum = sum % 11; 33 //printf("%d %d", sum,Dsum); 34 switch (Dsum) 35 { 36 case 0:Dealdentity[i++] = ‘1‘; 37 break; 38 case 1:Dealdentity[i++] = ‘0‘; 39 break; 40 case 2:Dealdentity[i++] = ‘x‘; 41 break; 42 case 3:Dealdentity[i++] = ‘9‘; 43 break; 44 case 4:Dealdentity[i++] = ‘8‘; 45 break; 46 case 5:Dealdentity[i++] = ‘7‘; 47 break; 48 case 6:Dealdentity[i++] = ‘6‘; 49 break; 50 case 7:Dealdentity[i++] = ‘5‘; 51 break; 52 case 8:Dealdentity[i++] = ‘4‘; 53 break; 54 case 9:Dealdentity[i++] = ‘3‘; 55 break; 56 case 10:Dealdentity[i++] = ‘2‘; 57 break; 58 } 59 for (i = 0; i < 18; i++) 60 { 61 printf("%c", Dealdentity[i]); 62 } 63 64 return 0; 65 }
直接建立数组查表:
1 #include<stdio.h> 2 int xishu[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 }; 3 char jieguo[11] = { ‘1‘,‘0‘,‘x‘,‘9‘,‘8‘,‘7‘,‘6‘,‘5‘,‘4‘,‘3‘,‘2‘ }; 4 int main() 5 { 6 char a[18]; 7 int b[18]; 8 int i, sum = 0; 9 gets(a); 10 for (i = 14; i >= 6; i--) 11 a[i + 2] = a[i]; 12 a[6] = ‘1‘; 13 a[7] = ‘9‘; 14 for (i = 0; i < 17; i++) 15 { 16 b[i] = a[i] - ‘0‘; 17 sum += b[i] * xishu[i]; 18 } 19 sum %= 11; 20 a[17] = jieguo[sum]; 21 for (i = 0; i < 18; i++) 22 printf("%c", a[i]); 23 printf("\n"); 24 return 0; 25 }
太傻了。。。
标签:for 数字串 style amp char i++ 输入格式 升级 gets
原文地址:https://www.cnblogs.com/ZhengLijie/p/12580450.html