从文件读入16进制数转化为10进制数再输出到文件中

sSN LMDscandata 1 1 B98C27 0 0 85C0 85C3 F55D73C5 F55DCC81 0 0 7 0 0 1388 168 0 1 DIST1 3F800000 00000000 DBBA0 1388 B5 136C 1373 136B 1389 1398 1356 136D 1386 137B 139C 13C4 13F7 1531 174D 1751 1755 1765 176C 1777 177B 1784 1791 1796 17A8 17C0 17C6 17C8 17E8 17F0 17FD 1802 180F 1824 1838 184A 184D 1862 1874 1890 189F 18AE 18BC 18DF 18E8 18FC 1910 1936 1946 1963 1976 1995 19A6 19BF 19E1 19FD 1A14 1A28 1A50 1A72 1A96 1AB1 1AD6 1AF1 1B10 1B37 1B58 1B83 1BAC 1BCE 1BF0 1C23 1C46 1C6C 1C98 1CC9 1D0F 1D34 1D69 1D99 1DC8 1DF9 1E35 1E6C 1EAB 1EDE 1F1E 1F40 1F94 1FDA 200E 2048 2090 20E3 212B 2178 21CA 2216 226C 22C5 2326 2376 23C6 2441 2499 2500 255A 25C3 262E 2692 2709 278B 2809 2894 2904 29A2 2A14 2ABA 2B54 2BDE 2C90 2D2A 2DE4 2EA8 2F7B 303F 3117 31DD 32BB 33B0 34C5 35CF 36B6 37E8 390C 3A22 3B57 3CD0 3E1C 3FA3 4151 42E1 44A9 4651 483E 4A1F 4C1E 4C3F 4D74 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0sSN LMDscandata 1 1 B98C27 0 0 85C1 85C4 F55DC248 F55E1B25 0 0 7 0 0 1388 168 0 1 DIST1 3F800000 00000000 DBBA0 1388 B5 1374 1376 1363 1384 139B 136A 1368 1388 1382 139D 13C7 13FF 1530 1746 175E 175B 1759 1769 177E 177A 1788 179C 17AC 17AD 17B9 17C7 17CF 17DC 17DF 17F4 1810 181E 1829 182E 1836 184E 1862 186D 1886 1890 18B2 18C6 18CC 18E3 18FE 1915 1929 1945 1965 197D 1990 19A6 19C5 19D1 19E8 1A1A 1A2C 1A49 1A70 1A9B 1AB1 1AD4 1AF9 1B11 1B3F 1B61 1B87 1BA4 1BD3 1BF3 1C12 1C4B 1C76 1C98 1CC7 1CF8 1D43 1D71 1D91 1DD0 1DFD 1E3C 1E6B 1EAA 1EE2 1F24 1F4C 1F94 1FCC 2008 204E 20A2 20E1 2134 217D 21C3 2211 2269 22BC 231B 237F 23DA 2432 249D 24F6 2562 25CB 263C 26A2 2705 2788 2809 2896 2921 299A 2A25 2AB8 2B53 2BDF 2C95 2D21 2DEC 2EA9 2F69 3028 3115 31E3 32BE 33AB 34B7 35A9 36D4 37EF 38F9

将他们转化为10进制 非16进制数直接输出

方法一:

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
    char c[1005];
    while(cin>>c)
    {
        if(strcmp(c,"sSN")==0)
        {
            cout<<c<<" ";
            continue;
        }
        else if(strcmp(c,"0sSN")==0)
        {
            cout<<c<<" ";
            continue;
        }
        else if(strcmp(c,"LMDscandata")==0)
        {
            cout<<c<<" ";
            continue;
        }
        else if(strcmp(c,"0")==0)
        {
            cout<<c<<" ";
            continue;
        }
        int len=strlen(c);
        long long i,ans=0,b=1,d;
        for(i=len-1;i>=0;i--)
        {
            if(c[i]>='A'&&c[i]<='F')
            d=c[i]-'A'+10;
            else
            d=c[i]-'0';
            ans+=b*d;
            b*=16;
        }
        cout<<ans<<" ";
    }
    return 0;
}

方法二:

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main()
{
    long long n;
    char c[1005];
    while(scanf("%s",c)!=EOF)
    {
        if(strcmp(c,"sSN")==0)
        {
            cout<<c<<" ";
            continue;
        }
        else if(strcmp(c,"0sSN")==0)
        {
            cout<<c<<" ";
            continue;
        }
        else if(strcmp(c,"LMDscandata")==0)
        {
            cout<<c<<" ";
            continue;
        }
        else if(strcmp(c,"0")==0)
        {
            cout<<c<<" ";
            continue;
        }
        sscanf(c,"%llx",&n); //从字符串读入一个数
        printf("%lld ",n);
    }
    return 0;
}

 把代码存成AC.cpp 把输入文件存成data.in 再新建一个文本文档 输入 AC < data.in > data.out 以后缀名bat保存

先把代码编译一下,会生成AC.exe。然后运行bat即可生成文件data.out

posted @ 2016-04-24 11:37  Ritchie丶  阅读(2738)  评论(5编辑  收藏  举报