信雅达面试题atoi函数实现
atoi函数:
#include <stdio.h>
#include <assert.h>
int is_digit(char ch)
{
if(ch >= '' && ch <= '')
return ;
else
return ;
}
int is_space(char ch)
{
if(ch == ' ' || '\n' == ch || '\t' == ch || '\r' == ch || '\b' == ch || '\f' == ch)
return ;
else
return ;
} int my_atoi(const char *str)
{
assert(str);
int sum = ;
char sign = '+'; while(is_space(*str++)); if(*str == '+' || *str == '-')
sign = *str++; while(is_digit(*str))
{
sum = sum * + *str - '';
str++;
} if(sign == '-')
return -sum;
else
return sum;
}
int main()
{
printf("string: %d\n", my_atoi("+214"));
return ;
}
信雅达面试题atoi函数实现的更多相关文章
- 一道经典面试题,atoi函数的实现
参考资料 (1)atoi函数的实现 (2)<剑指offer> 题目分析 本题需要注意的有几个方面: (1)检查输入参数,指针是否为NULL: (2)去除字符串前面的空格 (3)处理正负符号 ...
- atoi()函数
原型:int atoi (const char *nptr) 用法:#include <stdlib.h> 功能:将字符串转换成整型数:atoi()会扫描参数nptr字符串,跳过前 ...
- C语言itoa()函数和atoi()函数详解(整数转字符C实现)
1.int/float to string/array: C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串,下面列举了各函数的方法及其说明. ● itoa():将 ...
- 题目1003:A+B ---c_str(),atoi()函数的使用;remove , erase函数的使用
#include<stdio.h> #include<stdlib.h> int sw(char *a){ ,c=; while(a[i]){ ') c=c*+a[i]-'; ...
- atoi()函数的实现
atoi()函数的功能:将字符串转换成整型数:atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负号才开始做转换,而再遇到非数字或字符串时('\0')才结束转化,并将结果返回( ...
- C语言itoa()函数和atoi()函数详解(整数转字符)
http://c.biancheng.net/cpp/html/792.html C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串. 以下是用itoa()函数将整 ...
- C语言itoa函数和atoi 函数
C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串.以下是用itoa()函数将整数转 换为字符串的一个例子: # include <stdio.h> ...
- 【C语言】模拟实现atoi函数
atoi(表示 ascii to integer)是把字符串转换成整型数的一个函数. atoi()函数会扫描参数 nptr字符串,跳过前面的空白字符(例如空格,tab缩进等,可以通过isspace( ...
- String to Integer (atoi) - 字符串转为整形,atoi 函数(Java )
String to Integer (atoi) Implement atoi to convert a string to an integer. [函数说明]atoi() 函数会扫描 str 字符 ...
随机推荐
- CI - Set CSRF Hash and Cookie
/** * Set CSRF Hash and Cookie * * @return string */ protected function _csrf_set_hash() { if ($this ...
- 【UML】UML所扮演的角色(视频总结)
导读:在国庆中,把UML视频看完了.看完了之后,对于自己到底留下了什么呢,在此就总结一下,前面总结了UML的9种图以及主要的关系,本篇博客,就从整体上对UML做一个说明. 一.总体概述 UML一共讲了 ...
- js的undefined怎么判断
window.undefined=window.undefined 如何理解呢?百度搜索:window.undefined=window.undefined 博客说是为了兼容老浏览器. 技巧: 调试时 ...
- Git升级迁移
1 原有机器进行升级和备份: https://about.gitlab.com/update/#centos-6 1. Make a backup (Optional) If you would li ...
- rsync同步命令
rsync同步时,--delete删除目标目录比源目录多余文件的方法1 .实例说明 服务器A上同步/tmp/work目录到远程服务器B的/tmp/work目录下, 同时删除B服务器/tmp/work ...
- 【Luogu】P1896互不侵犯King(状压DP)
题目链接 真是可恶,被数据范围坑了一把.想要一遍AC的希望破灭了…… 以后大家在做状压DP的时候一定要开long long…… 设f[i][j][k]表示考虑前i行,总共放了j个King,第i行状态为 ...
- BZOJ 3669 [Noi2014]魔法森林 ——SPFA / Link-Cut Tree
[题目分析] 大意就是有一张图,边权有两个值,ai和bi 找到一条路径,使得路径上的max(ai)+max(bi)最小. 遇到有两个权值或者多个权值的时候,如果他们互相影响,试着用分块搞一搞. 如果互 ...
- hdu 3711
#include<stdio.h> #include<math.h> #include<stdlib.h> int cmp(const void *a,const ...
- ⑨要写信(codevs 1697)
题目描述 Description 琪露诺(冰之妖精)有操控冷气的能力.能瞬间冻结小东西,比普通的妖精更危险.一直在释放冷气的她周围总是非常寒冷. 由于以下三点原因…… 琪露诺的符卡 冰符“Icicle ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...