atoi的实现
#include <iostream>
using namespace std;
int atoi(char* s)
{
int retval=0;
int n=1;
if (*s=='-')
{
n=-1;
s++;
}
while (*s!='\0')
{
retval=retval*10+(*s-'0');
s++;
}
return(n*retval);
}
void main()
{
char s[6];
long n;
printf("Enter a string:\n") ;
gets(s);
n = atoi(s);
printf("%ld\n",n);
while(1);
}
atoi的实现的更多相关文章
- [LeetCode] String to Integer (atoi) 字符串转为整数
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- 编写atoi库函数
看到很多面试书和博客都提到编写atoi函数,在很多面试中面试官都会要求应聘者当场写出atoi函数的实现代码,但基本很少人能写的完全正确,倒不是这道题有多么高深的算法,有多么复杂的数据结构,只因为这道题 ...
- 行程编码(atoi函数)
#include<iostream> #include<string> #include<vector> using namespace std; void jie ...
- No.008:String to Integer (atoi)
问题: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...
- c/c++面试题(8)memcopy/memmove/atoi/itoa
1.memcpy函数的原型: void* memcpy(void* dest,cosnt void* src,size_t n); 返回值:返回dest; 功能:从源内存地址src拷贝n个字节到des ...
- LeetCode 7 -- String to Integer (atoi)
Implement atoi to convert a string to an integer. 转换很简单,唯一的难点在于需要开率各种输入情况,例如空字符串,含有空格,字母等等. 另外需在写的时候 ...
- [LeetCode] 8. String to Integer (atoi)
Implement atoi to convert a string to an integer. public class Solution { public int myAtoi(String s ...
- atoi()函数
原型:int atoi (const char *nptr) 用法:#include <stdlib.h> 功能:将字符串转换成整型数:atoi()会扫描参数nptr字符串,跳过前 ...
- [Leetcode]String to Integer (atoi) 简易实现方法
刚看到题就想用数组做,发现大多数解也是用数组做的,突然看到一个清新脱俗的解法: int atoi(const char *str) { ; int n; string s(str); istrings ...
- 【leetcode】atoi (hard) ★
虽然题目中说是easy, 但是我提交了10遍才过,就算hard吧. 主要是很多情况我都没有考虑到.并且有的时候我的规则和答案中的规则不同. 答案的规则: 1.前导空格全部跳过 “ 123” ...
随机推荐
- lightoj1057 - Collecting Gold (tsp问题)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1057 题目大意:在二维矩阵中,给你一个起点和至多15个的目标点.要你求出从起点出发经过 ...
- lost connection to mysql server reading initial communication packet
- reids-geo
Redis Geo Geo
- spring中解析xml
解析xml有SAX,Stax,dom等方式,那么spring中是如何解析xml文件的呢? Document doc = this.documentLoader.loadDocument( inputS ...
- [置顶] [MATLAB技术贴]漫谈MATLAB矩阵转置
矩阵转置是matlab最基本的操作了,但这个基本操作,也是很多初学者容易出现问题的地方.本帖通过几个实例演示matlab矩阵转置的操作. 方法一:' 运算符与 .' 运算符 >>a ...
- Unity3D开发类似保龄球游戏
先学习一些基本的脚本实现: 1.动态创建物体.默认位置是(0,0)位置 GameObject goNew = GameObject.CreatePrimitive(PrimitiveType.Cube ...
- linux上安装rar解压软件
描述:Linux默认自带ZIP压缩,最大支持4GB压缩,RAR的压缩比大于4GB. -------------------------------------------------- 下载 # wg ...
- win10安装MySQL
mysql的直接地址,可以复制地址使用下载工具下载:32位:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-win32.zip64位:htt ...
- Android摄像头抓取图像的格式
android.hardware.Camera.PreviewCallback /** * Callback interface used to deliver copies of preview f ...
- 最新Connectify注冊码(序列号) Connectify3.7序列号 破解版
Connectify序列号.最新注冊码 今天给大家公布一个Connectify最新版的序列号(注冊码) 今天给大家公布一个Connectify最新版的序列号(注冊码) 经本人測试该注冊码为最新版Con ...