atoi

1006 Sign In and Sign Out (25 分)

本秂侑毒 提交于 2019-12-04 11:37:58
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day. Input Specification: Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format: ID_number Sign_in_time Sign_out_time where times are given in the format HH:MM:SS , and ID

QtCreator调试遇到 #line 的问题

落花浮王杯 提交于 2019-12-04 05:41:44
今天调试一段代码的时候,遇到一个问题 如下图所示,代码中有 #line的关键字,导致了QtCreator无法调试,主要是不能正常的单步执行,我的开发环境是(vc2015) 于是给Qt官方提交bug, https://bugreports.qt.io/browse/QTCREATORBUG-23082 经过将近一个月的等待,终于等来了官方的回复。 其实这个问题原因不是 #line的问题,而是 atoi.rl 的问题,这个文件是中间代码,依靠它生成的C++代码会参与真正的项目编译,生成的代码里面在有需要的位置会使用#line来指示调试器重定位到atoi.rl,调试的时候还需要用到此文件。 在QtCreator环境中启动调试,默认只把 %{buildDir} 目录环境给了 cdb ,cdb在调试的时候,跟据上面的#Line指示的文件,在 %{buildDir} 目录中是找不到这个文件的,也导致单步执行定位失败,只能在栈上看到数据,却定位不到源代码的line位置。 解决方法就是 附加一个 cp 命令,自动把 atoi.rl 文件copy到 %{buildDir}中去。 见官方原始回复: It seems cdb is able to find the correct source location, because lsa with the address returned by x

LeetCode:String to Integer (atoi)

你。 提交于 2019-12-04 05:18:36
1、题目名称 String to Integer (atoi) (字符串到数字的转换) 2、题目地址 https://leetcode.com/problems/string-to-integer-atoi/ 3、题目内容 英文:Implement atoi to convert a string to an integer. 中文:实现atoi函数,将输入的字符串(String类型)转换为整型数据(Integer类型) 提示:实现的atoi函数需要满足以下特征 忽略字符串第一个非空格字符前的所有空格(whitespace),第一个非空格字符可以是正负号,后面接纯数字,atoi函数将这些纯数字转换为整型并返回 在数字字符后面可以接其他任何字符,但这些非数字的字符将被忽略 如果字符串中第一个非空格字符不是一个数字,字符串为空或仅由空格组成,则不对之进行转换 如果无法对字符串进行转换,返回0。如果取值过大或过小,返回整型数字的最大值INT_MAX(2147483647)或最小值INT_MIN(-2147483648) 4、解题方法1 可以使用Java中的Integer.parseInt函数解决问题,但Integer.parseInt函数与题目中描述的atoi在接收的输入上条件更为苛刻,因此需要将输入的字符串先转换为Integer.parseInt可以转换的形式

Creating an atoi function

荒凉一梦 提交于 2019-12-04 03:43:58
问题 I'm attempting to create my own atoi function. With the following I'm getting a return value of 0. Whatever I change the number variable within the function is what I get as a return value. Any suggestions on modifying the code? //my atoi function int atoi_me(char *numstring) { int number = 0; while((*numstring >= '0') && (*numstring <= '9')) { number = (number * 10) + (*numstring - '0'); numstring++; } return number; } int main() { char *number[MAXSIZE]; int num; printf("Please enter a

Convert std::string to integer

半腔热情 提交于 2019-12-03 12:04:23
问题 I'm trying to convert a std::string stored in a std::vector to an integer and pass it to a function as a parameter. This is a simplified version of my code: vector <string> record; functiontest(atoi(record[i].c_str)); My error is as follows: error: argument of type ‘const char* (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::)()const’ does not match ‘const char*’ How can I do this? 回答1: With C++11: int value = std::stoi(record[i]); 回答2: Use stringstream from standard

like atoi but to float

混江龙づ霸主 提交于 2019-12-03 10:51:00
Is there a function similar to atoi which converts a string to float instead of to integer? RED SOFT ADAIR atof() (or std::atof() talking C++ - thanks jons34yp ) boost::lexical_cast<float>(str); This template function is included in the popular Boost collection of libraries, which you'll want learn about if you're serious about C++. Convert a string to any type (that's default-constructible and streamable): template< typename T > T convert_from_string(const std::string& str) { std::istringstream iss(str); T result; if( !(iss >> result) ) throw "Dude, you need error handling!"; return result; }

LeetCode 8. 字符串转换整数 (atoi)

柔情痞子 提交于 2019-12-03 02:36:47
LeetCode 8. 字符串转换整数 (atoi) 请你来实现一个 atoi 函数,使其能将字符串转换成整数。 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。 当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。 该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可以被忽略,它们对于函数不应该造成影响。 注意:假如该字符串中的第一个非空格字符不是一个有效整数字符、字符串为空或字符串仅包含空白字符时,则你的函数不需要进行转换。 在任何情况下,若函数不能进行有效的转换时,请返回 0。 说明: 假设我们的环境只能存储 32 位大小的有符号整数,那么其数值范围为 [−231, 231 − 1]。如果数值超过这个范围,请返回 INT_MAX (231 − 1) 或 INT_MIN (−231) 。 示例 1: 输入: "42" 输出: 42 示例 2: 输入: " -42" 输出: -42 解释: 第一个非空白字符为 '-', 它是一个负号。 我们尽可能将负号与后面所有连续出现的数字组合起来,最后得到 -42 。 示例 3: 输入: "4193 with words" 输出: 4193 解释: 转换截止于数字

8. String to Integer (atoi) go语言

匿名 (未验证) 提交于 2019-12-03 00:43:02
go语言 func myAtoi(str string) int { len_str := strings.Count(str,"") - 1 var s string = "" for i := 0;i < len_str ; i++{ if str[i:i+1] == " " && s == ""{ continue }else if str[i:i+1] == "-" && s == ""{ s += "-" }else if str[i:i+1] == "+" && s == ""{ s += "+" }else if str[i:i+1] == "0" && (s == "+" || s == "-"){ continue }else if str[i:i+1] <= "9" && str[i:i+1] >= "0"{ s += str[i:i+1] }else{ break } } var j int = 0 for i := 0;i < strings.Count(s,"") - 1 ; i++{ if s[i:i+1] == "0"{ j++ }else{ break } } s = s[j:] if strings.Count(s,"") - 1 > 11 && s[0:1] == "-" { return -2147483648 }else if strings