1,請定義乙個巨集,比較兩個數a、b的大小,不能使用大於、小於、if語句 答:
#define max(a,b) ((a-b)+abs(a-b)) ? a : b
若a>b,則a-b和abs(a-b)均大於0,若a
2,如何輸出原始檔的標題和目前執行行的行數
複製**
#include
using namespace std;
int main()
複製**
3,兩個數相加,小數點後位數沒有限制,請寫乙個高精度演算法
複製**
/** *
* @author phinecos
* @since 2009-05-19 */
public class test
} else if(num2b.length() > num1b.length())
} //小數字對齊準備完畢,進行小數部分相加
string rstwo = add(num1b, num2b);
if (rstwo.length() > maxlen)
//兩部分結果拼湊起來
stringbuilder sb = new stringbuilder(rsone);
result = sb.tostring();
return result; }
private static string add(string num1, string num2)
else
}if (len1 > len2)
else
} }else if (len2 > len1)
else
} }if (naddon > 0)
sb.reverse();
result = sb.tostring();
return result; }
public static void main(string args) throws exception
} 複製**
4,對第3題做下修改,變成:兩個數相乘,小數點後位數沒有限制,請寫乙個高精度演算法。
複製**
/** *
* @author phinecos
* @since 2009-05-19 */
public class test
stringbuilder tmpsb = new stringbuilder(sum);
for (j = i; j < len1 -1; ++j)
result = add(result,tmpsb.tostring()); }
}else
stringbuilder tmpsb = new stringbuilder(sum);
for (j = i; j < len2 -1; ++j)
result = add(result,tmpsb.tostring()); }
}return result; }
private static string multipyfloatnum(string num1, string num2)
private static string add(string num1, string num2)
else
}if (len1 > len2)
else
} }else if (len2 > len1)
else
} }if (naddon > 0)
sb.reverse();
result = sb.tostring();
return result; }
public static void main(string args) throws exception
} 複製**
筆試練習 美團筆試題(一)
1 棋子翻轉 在4x4的棋盤上擺滿了黑白棋子,黑白兩色的位置和數目隨機其中左上角座標為 1,1 右下角座標為 4,4 現在依次有一些翻轉操作,要對一些給定支點座標為中心的上下左右四個棋子的顏色進行翻轉,請計算出翻轉後的棋盤顏色。給定兩個陣列a和f,分別為初始棋盤和翻轉位置。其中翻轉位置共有3個。請返...
筆試題練習(八)
1 不使用中間變數實現 strlen intstrlen p const char p 2,統計32位整數二進位制表示1的個數 bool ispowof2 intn intcountones intn return count int countzeros intn 3 題目 有乙個陣列 t 100...
筆試題練習(六)
1,輸入n,列印 n n螺旋矩陣 比如 n 3,列印 n 4,列印 1 2 3 4 109 8 7 author phinecos since 2005 05 27 public class test inti 上 for i n m i m i 右for i n m 1 i1 i 下 for i ...