美文网首页
分割数字

分割数字

作者: Co_zy | 来源:发表于2018-08-01 14:04 被阅读0次

    给出一个身份证号,输出对应地区以及出生年月
    330000199602145632
    330000 19960214 5632

    1.将这个数组分离然后存储到数组,再转成字符串,然后去比对对应的地名
    2.多组输入,当时每次输入得到的都是相同的结果,执行完一次需要将数组计数变量置0

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    char *getCountry(char *country)
    {
        if(strcmp(country,"333000")==0)
            return "Beijing";
        else if(strcmp(country,"111000")==0)
            return "Taiwan";
        return 0;
    }
    
    
    int main()
    {
        long long input;
        int n;
        int i;
        int country[1000];
        int con1[1000];
        char country1[1000];
        int j=0,k=0;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%lld",&input);
            while(input!=0)
            {
                country[j++] = input % 10;
                input /= 10;
            }
            for(i=j-1; i>=0; i--)
            {
                con1[k++] = country[i];
            }
            for(i=0; i<6; i++)
            {
                country1[i] = con1[i] + '0';
            }
            country1[6] = '\0';
            //printf("%s\n",country1);
            printf("%s\n",getCountry(country1));
            j = 0;
            k = 0;
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:分割数字

          本文链接:https://www.haomeiwen.com/subject/axukvftx.html