digit

Determine if a number contains a digit for class assignment

牧云@^-^@ 提交于 2021-01-16 04:07:58
问题 Write a function named containsDigit that determines if a number contains a particular digit. The header should look like: bool containsDigit(int number, int digit); If number contains digit, then the function should return true . Otherwise, the function should return false . Input: 147 9 Output: false I don't know why I always get false when I write like this: bool containsDigit(int number, int digit); int main() { double con; int number, digit; cout << "Input a number and a digit:\n"; cin >

Determine if a number contains a digit for class assignment

久未见 提交于 2021-01-16 04:02:39
问题 Write a function named containsDigit that determines if a number contains a particular digit. The header should look like: bool containsDigit(int number, int digit); If number contains digit, then the function should return true . Otherwise, the function should return false . Input: 147 9 Output: false I don't know why I always get false when I write like this: bool containsDigit(int number, int digit); int main() { double con; int number, digit; cout << "Input a number and a digit:\n"; cin >

Determine if a number contains a digit for class assignment

一笑奈何 提交于 2021-01-16 04:01:06
问题 Write a function named containsDigit that determines if a number contains a particular digit. The header should look like: bool containsDigit(int number, int digit); If number contains digit, then the function should return true . Otherwise, the function should return false . Input: 147 9 Output: false I don't know why I always get false when I write like this: bool containsDigit(int number, int digit); int main() { double con; int number, digit; cout << "Input a number and a digit:\n"; cin >

Using regex to check if a string contains only one digit

梦想的初衷 提交于 2020-12-12 05:10:50
问题 I'm writing an algorithm and I need to check if a string contains only one digit (no more than one). Currently I have: if(current_Operation.matches("\\d")){ ... } Is there a better way to go about doing this? Thanks. 回答1: You can use: ^\\D*\\d\\D*$ # match beginning of the line # non digits - \D* # one digit - \d # non digits - \D* # end of the line $ See a demo on regex101.com (added newlines for clarity). 回答2: If you fancied not using a regular expression: int numDigits = 0; for (int i = 0;

Regex : Phone number starting with 06 or 07

允我心安 提交于 2020-07-30 14:16:50
问题 I have this function which works only for 10 digits. function telValide( tel ) { var reg = new RegExp('^[0-9]{10}$', 'i'); return reg.test(tel); } I would like to check phone number starting with 06 or 07 . Ex : 06 01010101 : true 07 01240101 : true 00 04343000 : false 回答1: var reg = new RegExp('^((06)|(07))[0-9]{8}$', 'i'); 回答2: I guess it's a simple case: ^0[67][0-9]{8}$ 回答3: '^0(6|7) [0-9]{8}$' Or if you mean you want the numbers without a space: '^0(6|7)[0-9]{8}$' Check out some excellent

Regex : Phone number starting with 06 or 07

被刻印的时光 ゝ 提交于 2020-07-30 14:15:57
问题 I have this function which works only for 10 digits. function telValide( tel ) { var reg = new RegExp('^[0-9]{10}$', 'i'); return reg.test(tel); } I would like to check phone number starting with 06 or 07 . Ex : 06 01010101 : true 07 01240101 : true 00 04343000 : false 回答1: var reg = new RegExp('^((06)|(07))[0-9]{8}$', 'i'); 回答2: I guess it's a simple case: ^0[67][0-9]{8}$ 回答3: '^0(6|7) [0-9]{8}$' Or if you mean you want the numbers without a space: '^0(6|7)[0-9]{8}$' Check out some excellent

Regex : Phone number starting with 06 or 07

别等时光非礼了梦想. 提交于 2020-07-30 14:14:23
问题 I have this function which works only for 10 digits. function telValide( tel ) { var reg = new RegExp('^[0-9]{10}$', 'i'); return reg.test(tel); } I would like to check phone number starting with 06 or 07 . Ex : 06 01010101 : true 07 01240101 : true 00 04343000 : false 回答1: var reg = new RegExp('^((06)|(07))[0-9]{8}$', 'i'); 回答2: I guess it's a simple case: ^0[67][0-9]{8}$ 回答3: '^0(6|7) [0-9]{8}$' Or if you mean you want the numbers without a space: '^0(6|7)[0-9]{8}$' Check out some excellent

Regex : Phone number starting with 06 or 07

不打扰是莪最后的温柔 提交于 2020-07-30 14:12:44
问题 I have this function which works only for 10 digits. function telValide( tel ) { var reg = new RegExp('^[0-9]{10}$', 'i'); return reg.test(tel); } I would like to check phone number starting with 06 or 07 . Ex : 06 01010101 : true 07 01240101 : true 00 04343000 : false 回答1: var reg = new RegExp('^((06)|(07))[0-9]{8}$', 'i'); 回答2: I guess it's a simple case: ^0[67][0-9]{8}$ 回答3: '^0(6|7) [0-9]{8}$' Or if you mean you want the numbers without a space: '^0(6|7)[0-9]{8}$' Check out some excellent

[leetcode] String to Integer (atoi)

亡梦爱人 提交于 2020-04-10 08:19:57
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 below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front. Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as