采用輾轉(zhuǎn)相除法; 輾轉(zhuǎn)相除法百度百科 代碼:C++非遞歸實現(xiàn)
int gcd(int a,int b){ int temp = 0; while(b) { temp = b; b = a % b; a = temp; } return a;}C++遞歸實現(xiàn)
gcd(int a,int b){ return a%b?gcd(b,a%b):b;}最小公倍數(shù)與最大公約數(shù)之間存在著(a,b) * 【a,b】 = a*b;的關(guān)系
int lcm(int a,int b){ return a*b/gcd(a,b);}結(jié)構(gòu)體sort:
bool cmp(node a,node b){ return a.x>b.y;}絕對值排序
int cmp(int a,int b){ return abs(a) < abs(b);}abs函數(shù),函數(shù)頭文件為:math.h/cmath
pow函數(shù),函數(shù)頭文件:math.h/cmath
頭文件: string, cctype,algorithm
transform(str.begin(),str.end(),str.begin(),tolower);//大寫轉(zhuǎn)小寫transform(s.begin(), s.end(), s.begin(), toupper);//小寫轉(zhuǎn)大寫
|
新聞熱點
疑難解答