# UVa 11936 ### 題目連結:[UVa11936](http://domen111.github.io/UVa-Easy-Viewer/?11936) ### 題述: 從前,從前,在遙遠的森林中有一群懶惰的伐木工人。因為他們很懶,不想砍樹木,所以總是想辦法不工作。但另一方面,工頭總是想要叫他們回去工作。 經過許多的討論後,工頭和工人達成協議:伐木工人會工作,只要被指定給他們的工作區域是一個三角形。方法是給三個整數代表這三角形的邊長,只要這三個數字可以構成一個三角形,伐木工人就得工作,否則他們就可以放假了。 由 於這些伐木工人也很狡猾,他們說服工頭讓他們決定這三個數字。因此,這些伐木工人老是給三個不能構成三角形的數字。經過一段日子,工頭決定寫一個程式來驗 證伐木工人給的三個數字可否構成三角形。現在,一旦工人給的數字不能構成三角形,他們就得罰款$1000元(比一天的工資還多)。 你的任務就是幫工頭寫這個驗證的程式。輸入伐木工人給的三個邊長,請你判斷**是否這三個邊能構成一個三角形**。 --- 第一列有一個整數 N ( 2 <= N <= 20 )表示測試資料的組數,接下來N列,每列有三個整數表示伐木工人給的三邊長。 --- 請每組資 料分別輸出 "OK" 表示可構成三角形, "Wrong!!" 表示不能構成三角形。 ### c++ code: ```cpp= #include<iostream> using namespace std; int main() { //------------------------------------------------ #ifdef local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //------------------------------------------------ int n ; cin >> n ; while ( n != 0 ) { n -= 1 ; int d[3] ; for ( int i = 0 ; i < 3 ; i++ ) { cin >> d[i] ; } if ( d[0] + d[1] <= d[2] ) { cout << "Wrong!!" << endl ; } else if ( d[2] + d[1] <= d[0] ) { cout << "Wrong!!" << endl ; } else if ( d[2] + d[0] <= d[1] ) { cout << "Wrong!!" << endl ; } else { cout << "OK" << endl ; } } } ``` :::success **``sample input``** 6 1 2 3 3 2 5 3 4 5 6 6 1 3 3 3 7 3 10 ::: :::success **``sample output``** Wrong!! Wrong!! OK OK OK Wrong!! ::: #### [返回首頁](https://hackmd.io/@fkleofk/APCS#11936) ###### tags: `APCS選修` `C++` `UVa`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up