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” ...
随机推荐
- hdu 4465 Candy(二次项概率)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4465 参考博客:http://www.cnblogs.com/goagain/archive/2012 ...
- hdu 4403 枚举
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> #inclu ...
- springMVC能做什么,做j2ee时候要考虑什么
转载: http://jinnianshilongnian.iteye.com/category/231099 [置顶] 跟我学SpringMVC目录汇总贴.PDF下载.源码下载 博客分类: 跟开涛学 ...
- openStack opts
- Python切割nginx日志_小组_ThinkSAAS
Python切割nginx日志_小组_ThinkSAAS Python切割nginx日志
- nORA-01000: 超出打开游标的最大数(SDE连接)
1.运行ArcObjects代码报错: IFeatureCursor pCursor = null; try { pCursor = m_pCatchLayer.m_pFeatureClass.Sea ...
- bzoj 2741 分块+可持久化trie
多个询问l,r,求所有子区间异或和中最大是多少 强制在线 做法: 分块+可持久化trie 1.对于每块的左端点i,预处理出i到任意一个j,()i,j)间所有子区间异或和中最大为多少,复杂度O(\(n\ ...
- Python基础知识--列表和集合
列表:有序性,可以存放任意类型的对象,通过索引访问,可以分片操作 >>> L = ['id', 1000, 'scd', 1000, 'scd'] >>> L [' ...
- Cocos2d-x 3.0 红孩儿私家必修 - 第二章 cpp-empty-test
上一章我们讲到说曾经的HelloWorld演示更名为cpp-empty-test. 本章我们来分析一下 执行程序,我们能够看到熟悉的HelloWorld程序:与之前cocos2d-x2.x版本号的He ...
- 初步掌握HDFS的架构及原理
目录 HDFS 是做什么的 HDFS 从何而来 为什么选择 HDFS 存储数据 HDFS 如何存储数据 HDFS 如何读取文件 HDFS 如何写入文件 HDFS 副本存放策略 Hadoop2.x新特性 ...