由买买提看人间百态

topics

全部话题 - 话题: curdigit
(共0页)
u***8
发帖数: 1581
1
103页。那个电话号码对应字母的题目。为什么for loop里面,要在最后判断是不是等
于0 或者是1?
getCharKey(int , int )不就是可以把一个数字对应的3个之一的字母给返回了么?那
么是0或者是1,就返回空的不就够了。为什么要判断下0 1,这个不懂。
updates: code在这里
static final int PHONE_NUMBER_LENGTH = 7;
void printTelephoneWords(int[] phoneNum) {

char[] result = new char [PHONE_NUMBER_LENGTH];
doPrintTelephoneWords( phoneNum, 0, result);
}
void doPrintTelephoneWords(int[] phoneNum, int curDigit, char[] result) {
if ( curDigit == PHONE_NUMBER_LENGTH) {
System.out.println(new S... 阅读全帖
l******6
发帖数: 340
2
来自主题: JobHunting版 - 请问,string to long
long long int transfor(const char* src){
long long int preMax = LLONG_MAX / 10;
int lastDigit = LLONG_MAX % 10;
long long int ret = 0;
bool sign = 1;
int curDigit;
while(*src == ' ')
src ++;
if(*src == '+' || *src == '-')
{
sign = *src == '-'? 0 : 1;
src ++;
}
while(isdigit(*src))
{
curDigit = *src - '0';
if(ret > preMax || ret == preMax && curDigit > lastDigit)
return sign? LLONG_MAX:LLONG_MIN;
... 阅读全帖
c***2
发帖数: 838
3
来自主题: JobHunting版 - map numbers to strings
1) from facebook
2) result[..+1] you can do that, but not necessary since C does index from 0
, the last idx is alwasy reseved for 0.
char try[2];
Either of these are fine:
try[0]='a';
try[1]='b';
try[2]='\0';
or strcpy(try,"ab");
3) curDigit is better named currentidx (from phoneNum[])
j***y
发帖数: 2074
4
来自主题: JobHunting版 - map numbers to strings
又琢磨了半天,你是对的。确实不需要再加一个循环,我搞错了。
就以你原来的程序为例:
doPr(p, 0, res) ->
currDigIdx=0, i=0, res[0]='d', doPr(p, 1, res) ->
currDigIdx=1, i=0, res[1]='a', doPr(p, 2, res) ->
print("da"), return ->
/* recursion-cycle finished for doPr(p, 2, res), but not finished yet for
doPr(p, 1, res) */
currDigIdx=1, i=1, res[1]='b', doPr(p, 2, res) ->
print("db"), return ->
currDigIdx=1, i=2, res[1]='c', doPr(p, 2, res) ->
print("dc"), return ->
/* now doPr(p, 1, res) is finished, return to the for-loop in doPr(p, 0,,
res... 阅读全帖
(共0页)