Re: [問題] 字串排列最大值
看板C_and_CPP (C/C++)作者tsaiminghan (nahgnimiast)時間16年前 (2009/03/05 01:34)推噓1(1推 0噓 0→)留言1則, 1人參與討論串4/4 (看更多)
: {
: if( *(str1 + pos) == 0 )
: return CompareInt( *str1, *(str2 + pos) );
: if( *(str2 + pos) == 0 )
: return CompareInt( *(str1 + pos), *str2 );
: if( ( res = CompareInt(*(str1 + pos), *(str2 + pos) ) ) == 0 )
: pos++;
: else
: return res;
剛才想了一下
上面的比較對於
123 123123000會出問題。
所以乾脆把
短字串重複複制到跟長字串長度一樣後,再用strcmp比
不過要動記憶體的話好像很更慢
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.99.246
※ 編輯: tsaiminghan 來自: 218.167.99.246 (03/05 01:35)
※ 編輯: tsaiminghan 來自: 218.167.99.246 (03/05 01:42)
推
03/05 16:52, , 1F
03/05 16:52, 1F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章