| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1516 人关注过本帖
标题:超难想!!!!想来试试就快来看看吧!!!
只看楼主 加入收藏
dousao
Rank: 2
等 级:论坛游民
帖 子:228
专家分:58
注 册:2007-11-8
收藏
得分:0 
复杂....中国人恐怕都在钻这个东西了.
2007-12-13 16:07
许一民
Rank: 1
来 自:江苏连云港
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-9-29
收藏
得分:0 
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*可以把2~36进制的数转换为十进数*/
int main()
{
    int i,soc,len,*num,yn;
    unsigned long int res;
    char s[100];

    printf("Please input the system of computation:\n");   //原数制2~36
    scanf("%d",&soc);

    printf("Please input the source data:\n");  //输入原数
    scanf("%s",s);

    len=strlen(s);

    /*printf("STRint LENght=%d\n",len);
    strlwr(s);
    puts(s);*/

    num=calloc(len,sizeof(int));

    if(soc>=2 && soc <=10)
        for(i=0;i<len;i++)
        {
            if(s[i]>='0'&&s[i]<='0'+soc-1)
                num[i]=s[i]-'0';
            else
            {
                printf("Input Error!\n");
                goto end;
            }
        }


    else if(soc>10 && soc<=36)
        for(i=0;i<len;i++)
        {
            if(s[i]>='0'&&s[i]<='9')
                num[i]=s[i]-'0';
            else if(s[i]>='a'&&s[i]<='a'+soc-11)
                num[i]=s[i]-'a'+10;
            else
            {
                printf("Input Error!\n");
                goto end;
            }
        }
    else
    {
        printf("The system of computation ERROR!");
        goto end;
    }

    res = num[0];

    for(i=1;i<len;i++)
    {
        res*=soc;
        res+=num[i];
    }

    printf("The result=%d\n",res);        //十进制结果

    end: ;
    return 0;
}

[[italic] 本帖最后由 许一民 于 2007-12-18 14:38 编辑 [/italic]]

丛丛芳芫满冬秋,淡淡一笑泯恩仇!
2007-12-18 14:34
快速回复:超难想!!!!想来试试就快来看看吧!!!
数据加载中...
 
   



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

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