#include<stdio.h>
#define MAXLINELEN 1000
int power(int base,int n)
{
int i=;
int answer=;
for(i=;i<n;i++)
answer=answer*base;
return answer;
}
/*strlen函数:返回s的长度*/
int strlen(char *s)
{
int i;
i=;
while(s[i]!='\0')
++i;
return i;
}
/*getline函数*/
void getlines(char *s)
{
int i=;
int lim=MAXLINELEN;
int c;
for(i=;i<lim-&&(c=getchar())!='\n'&&c!=EOF;i++)
s[i]=c;
}
/*hexalpha_to_int函数:把单个char转换成int*/
int hexalpha_to_int(int c)
{
if(c>=''&&c<='')
c=c-'';
else if(c>='a'&&c<='z')
c=c-'a'+;
else if(c>='A'&&c<='Z')
c=c-'A'+;
return c;
}
/**/
int htoi(char s[])
{
int len;
int i;
len=strlen(s);
int answer=;
if(s[]==''&&(s[]=='X'||s[]=='x'))
{
for(i=;i<len;i++)
{
answer=hexalpha_to_int(s[i])*power(,len--i)+answer;
}
}
else
{
for(i=;i<len;i++)
{
answer=hexalpha_to_int(s[i])*power(,len--i)+answer;
printf("i:%d\n",i);
printf("hexalpha_to_int(s[i]):%d\n",hexalpha_to_int(s[i]));
printf("power(16,len-1-i):%d\n",power(,len--i));
printf("answer:%d\n",answer);
}
}
return answer;
}
main()
{
char s[MAXLINELEN];
getlines(s);
printf("%d\n",htoi(s));
}

the c programming language 2-3的更多相关文章

  1. iOS Swift-元组tuples(The Swift Programming Language)

    iOS Swift-元组tuples(The Swift Programming Language) 什么是元组? 元组(tuples)是把多个值组合成一个复合值,元组内的值可以使任意类型,并不要求是 ...

  2. iOS Swift-控制流(The Swift Programming Language)

    iOS Swift-控制流(The Swift Programming Language) for-in 在Swift中for循环我们可以省略传统oc笨拙的条件和循环变量的括号,但是语句体的大括号使我 ...

  3. iOS Swift-简单值(The Swift Programming Language)

    iOS Swift-简单值(The Swift Programming Language) 常量的声明:let 在不指定类型的情况下声明的类型和所初始化的类型相同. //没有指定类型,但是初始化的值为 ...

  4. Java Programming Language Enhancements

    引用:Java Programming Language Enhancements Java Programming Language Enhancements Enhancements in Jav ...

  5. The Swift Programming Language 英文原版官方文档下载

    The Swift Programming Language 英文原版官方文档下载 今天Apple公司发布了新的编程语言Swift(雨燕)将逐步代替Objective-C语言,大家肯定想学习这个语言, ...

  6. The Swift Programming Language 中文翻译版(个人翻新随时跟新)

    The Swift Programming Language --lkvt 本人在2014年6月3日(北京时间)凌晨起来通过网络观看2014年WWDC 苹果公司的发布会有iOS8以及OS X 10.1 ...

  7. [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01

    注:CocoaChina翻译小组已着手此书及相关资料的翻译,楼主也加入了,多人协作后的完整译本将很快让大家看到. 翻译群:291864979,想加入的同学请进此群哦.(本系列不再更新,但协作翻译的进度 ...

  8. Questions that are independent of programming language. These questions are typically more abstract than other categories.

    Questions that are independent of programming language.  These questions are typically more abstract ...

  9. What is the Best Programming Language to Learn in 2014?

    It’s been a year since I revealed the best languages to learn in 2013. Once again, I’ve examined the ...

  10. C: Answers to “The C programming language, Edition 2”

    <The C programming language> Edition 2的习题答案地址: http://users.powernet.co.uk/eton/kandr2/index.h ...

随机推荐

  1. Tyvj P3119 核电站问题 动态规划

    题目:http://tyvj.cn/p/3119 P3119 核电站问题 时间: 1000ms / 空间: 65536KiB / Java类名: Main 描述 一个核电站有N个放核物质的坑,坑排列在 ...

  2. 广州Uber优步司机奖励政策(2月1日~2月7日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. PHP如何取出数组最后一个元素?

    <?php $array=array("first","sencond","third"); #1.echo end($array); ...

  4. php开发中的页面跳转方法总结

    PHP页面跳转实现的功能就是将网站中一个网页跳转到另一个网页中.对于刚刚学习PHP语言的朋友来说,是必须要掌握的基础方法. 页面跳转可能是由于用户单击链接.按钮等触发的,也可能是系统自动产生的.页面自 ...

  5. jvm内存GC详解

    一.相关概念  a. 基本回收算法 1. 引用计数(Reference Counting)  比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数.垃圾回收时,只用收 ...

  6. lcx源代码以及免杀的研究

    之前和Random大神讨论了一下免杀的问题,他给出了一个比较不错的想法,使用debug版本发布可以过很多杀软.顺便看了下lcx的源码,发现其代码不算特别复杂,于是乎就在这分析一下. 报毒情况 因为使用 ...

  7. 【转】Android应用开发allowBackup敏感信息泄露的一点反思

    转载:http://blog.csdn.net/yanbober/article/details/46417531 1 背景 其实这篇文章可能有些小题大作,但回过头想想还是很有必要的,有点阴沟里翻船的 ...

  8. 安卓开发中Theme.AppCompat.Light的解决方法

    styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...

  9. PHP中输出缓冲

    在PHP中,当运行echo,print的时候,输出并没有马上通过tcp传给client浏览器显示, 而是将数据写入php buffer.php output_buffering机制,意味在tcp bu ...

  10. 启动hadoop,报错Error JAVA_HOME is not set and could not be found

    报如错误:JAVA_HOME is not set and could not be found,可能是因为JAVA_HOME环境没配置正确,还有一种情况是即使各结点都正确地配置了JAVA_HOME, ...