2022.11.18 PM 04:40 by CBJ
來源 : https://zerojudge.tw/ShowProblem?problemid=d065 出題者 : snail蝸牛 標籤 : max()、if 難易度 : 1
解題想法 : 此題可以用單純的if來實作,亦可直接使用max()函式來完成(C語言需另外定義max(a,b),可使用函數宣告或巨集) 注意事項 : C++中提供的max()函式只接受一次比較兩個數,因此不能像Python一樣直接寫max(a,b,c),實作上可以先比較b,c求出較大值,在拿它去和a比,實際寫成程式碼會像這樣 : max(a, max(b, c)) 關於巨集(macro)的說明 : http://kaiching.org/pydoing/cpp/cpp-macro.html
//C language
//solution link(含註解):
#include<stdio.h>
#define max(a,b) ((a>b)?a:b)
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%d",max(a,max(b,c)));
return 0;
}

//C++ language
//solution link(含註解):
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<max(a,max(b,c))<<"\n";
return 0;
}

## Python language
## solution link(含註解):
print(max([int(x) for x in input().split()]))

發佈留言