| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 938 人关注过本帖
标题:身份证最后一位怎么确认 求路过大神指点
取消只看楼主 加入收藏
Ever0123
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2020-11-12
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:0 
身份证最后一位怎么确认 求路过大神指点
问题是根据输入的身份证号码确认最后一位数字对不对;
#include<stdio.h>
#include<string.h>
int main()
{
    char st[20];
    int T, i, j , sum = 0;
    scanf("%d", &T);
    while (T--)
    {
        sum = 0;
        scanf("%s", st);
        int len;
        len = strlen(st);
        if (len == 18)
        {
            for (i = 0; i < 17; i++)
            {
                switch (i)
                {
                case 0:sum += (st[i] - '0') * 7; break;
                case 1:sum += (st[i] - '0') * 9; break;
                case 2:sum += (st[i] - '0') * 10; break;
                case 3:sum += (st[i] - '0') * 5; break;
                case 4:sum += (st[i] - '0') * 8; break;
                case 5:sum += (st[i] - '0') * 4; break;
                case 6:sum += (st[i] - '0') * 2; break;
                case 7:sum += (st[i] - '0') * 1; break;
                case 8:sum += (st[i] - '0') * 6; break;
                case 9:sum += (st[i] - '0') * 3; break;
                case 10:sum += (st[i] - '0') * 7; break;
                case 11:sum += (st[i] - '0') * 9; break;
                case 12:sum += (st[i] - '0') * 10; break;
                case 13:sum += (st[i] - '0') * 5; break;
                case 14:sum += (st[i] - '0') * 8; break;
                case 15:sum += (st[i] - '0') * 4; break;
                case 16:sum += (st[i] - '0') * 2; break;
                }
            }
            int yu;
            yu = sum % 11;
            char re;
            switch (yu)
            {
            case 0:re = '1'; break;
            case 1:re = '0'; break;
            case 2:re = 'X'; break;
            case 3:re = '9'; break;
            case 4:re = '8'; break;
            case 5:re = '7'; break;
            case 6:re = '6'; break;
            case 7:re = '5'; break;
            case 8:re = '4'; break;
            case 9:re = '3'; break;
            case 10:re = '2'; break;
            }
            if (re == st[17])
                printf("right\n");
            else
                printf("wrong\n");
 
        }
    }
    return 0;
}
这个代码在oj上可以通过,但是在电脑上不会运行
搜索更多相关主题的帖子: break sum 过大 case int 
2020-11-26 11:00
快速回复:身份证最后一位怎么确认 求路过大神指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018562 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved