#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. ARM学习笔记11——GNU ARM汇编程序设计

    GNU ARM汇编程序设计中,每行的语法格式如下: [<label>:] [<instruction | directive | pseudo-instruction>] @c ...

  2. FZOJ--2221-- RunningMan 福建第六届省赛

    题目链接:http://acm.hust.edu.cn/vjudge/contest/127149#problem/J 题目大意: 因为总共就分三个队,因为两个队都要选取最优的策略,不论B队咋放,要使 ...

  3. .net常見面試題(一)

    2 .列举ASP.NET 页面之间传递值的几种方式. 答. 1).使用QueryString, 如....?id=1; response. Redirect()....                 ...

  4. malloc的实现

    在做csapp的malloc实验,一开始是按照书上的隐式链表法,发现得分很低.这种方法确实很挫,需要遍历一遍以找到合适的空闲块.于是我想到<STL源码剖析>中stl的内存池,感觉应该可以用 ...

  5. usaco 土地并购 && hdu 玩具装箱

    土地并购: Description 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土地,价格就是土地的面积.但他可以选择并购一组土地,并购的价格为这些土地中最大的长乘以最大 ...

  6. php class中public,private,protected的区别,以及实例

    一,public,private,protected的区别 public:权限是最大的,可以内部调用,实例调用等. protected: 受保护类型,用于本类和继承类调用. private: 私有类型 ...

  7. 【Caffe 测试】Training LeNet on MNIST with Caffe

    Training LeNet on MNIST with Caffe We will assume that you have Caffe successfully compiled. If not, ...

  8. Using Java SecurityManager to grant/deny access to system functions

    In Java it is possible to restrict access to specific functions like reading/writing files and syste ...

  9. JavaScript面向对象继承方法

    JavaScript的出现已经将近20多年了,但是对这个预言的褒贬还是众说纷纭.很多人都说JavaScript不能算是面向对象的变成语言.但是JavaScript的类型非常松散,也没有编译器.这样一来 ...

  10. NoSQL数据库的四大分类表格分析