题目: Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see be....
分类:
编程语言 时间:
2014-08-07 12:08:49
阅读次数:
260
这个我就直接上代码了,最开始把“abc123“也算作合法的了,后来查了一下atoi的定义,把这种去掉了。
public class Solution {
public static int atoi(String inStr) {
long result = 0L;
/*
* 网上查了一下,atoi函数的定义是如果第一个非空格字符存在,是数字或者正负号则开始做类型转换,
*...
分类:
其他好文 时间:
2014-08-06 10:36:31
阅读次数:
193
排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34364 Accepted Submission(s): 9654
Problem Description
输入一行数字,如果我们把这行数字中的‘5...
分类:
其他好文 时间:
2014-08-05 15:50:49
阅读次数:
211
Data Structures
1. Integer
– find number of 1s
– next largest smaller
– smallest larger number
– determine if is palindrom
– itoa, atoi
– add 2 numbers w/...
分类:
其他好文 时间:
2014-08-05 15:50:40
阅读次数:
408
问题:将字符窜转换成数字分析:感觉题目不难,但是细节很多,容易想不到1.数字前面有空格 如s=“ 123456”2.数字前出现了不必要或多于的字符导致数字认证错误,输出0 如s=“ b1234” ,s=“ ++1233” , s=“ +-1121”3.数字中出现了不必要的字符,返回字符前的数字...
分类:
其他好文 时间:
2014-08-02 12:36:23
阅读次数:
301
Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ...
分类:
其他好文 时间:
2014-08-01 04:35:11
阅读次数:
219
1. c++中string到int的转换1) 在C标准库里面,使用atoi:#include #include std::string text = "152"; int number = std::atoi( text.c_str() ); if (errno == ERANGE) //可能是s....
分类:
编程语言 时间:
2014-07-31 19:48:27
阅读次数:
294
问题描述:
Implement atoi to convert a string to an integer.
解题思路:
对于一个字符串需要注意一下几点:
1、过滤字符串开头的所有空格字符;
2、注意数字字符前面的“+”和“-”字符,从而确定数字的正负号;
3、只处理数字字符,一旦出现非数字字符,立即停止字符串处理,并返回已处理的结果;
4、返回结果时要注意数字越界的问题,不能...
分类:
其他好文 时间:
2014-07-31 00:03:45
阅读次数:
314
注意问题:
1)字符串是空指针的情况。
2)如果输入的是一个空字符串“”
3)所有‘0’到‘9’之外的字符都是非法的吗?加号和减号是合法输入。
4) 考虑溢出
#include
using namespace std;
bool g_value=false;
int atoi(char * number){
if(number == NULL || *nu...
分类:
其他好文 时间:
2014-07-30 17:37:04
阅读次数:
182
解法:考虑多种情况 1 #include 2 3 class Solution { 4 public: 5 int atoi(const char *str) { 6 int signal = 0; /*标记正负,还未出现判定正负的标志时,记为0*/ 7 ...
分类:
其他好文 时间:
2014-07-30 11:57:03
阅读次数:
182