--- tags: 蘿莉控自學 --- > 蘿莉控的C++自學筆記 # c060: 00392 - Polynomial Showdown 連結: https://zerojudge.tw/ShowProblem?problemid=c060 AC(2ms, 316KB) ```cpp= #include<bits/stdc++.h> using namespace std; int a[10]; int main() { int a0; while(cin >> a0) { a[0] = a0; bool zero = true; for(int i = 1; i < 9; i ++) { cin >> a[i]; if (a[i] != 0) zero = false; } bool fir = true; for(int i = 0; i < 9; i ++) { if (a[i] == 0 ) continue; if (fir) { if (a[i] > 0) { if(i == 8) { if (a[i] < 0) { cout << "-" << abs(a[i]) ; continue; } cout << "+" << a[i] ; continue; } if(i == 7) { if (a[i] == 1) { cout << "+" <<"x"; continue; } else if(a[i] == -1) { cout << "-"<<"x"; continue; } if (a[i] < 0) { cout << "-" << abs(a[i]) << "x"; continue; } cout << "+" << a[i] << "x"; continue; } if (a[i] == 1) { cout << "x^" << 8-i; fir = false; continue; } cout << a[i] << "x^" << 8-i; fir = false; continue; } else { if(i == 8) { if (a[i] < 0) { cout << "-" << abs(a[i]) ; continue; } cout << "+" << a[i] ; continue; } if(i == 7) { if (a[i] == 1) { cout << "+" <<"x"; continue; } else if(a[i] == -1) { cout << "-"<<"x"; continue; } if (a[i] < 0) { cout << "-" << abs(a[i]) << "x"; continue; } cout << "+" << a[i] << "x"; continue; } if (a[i] == -1 && i != 8) { cout << "-" << "x^" << 8-i; fir = false; continue; } cout << a[i] << "x^" << 8-i; fir = false; continue; } if(i == 8) { if (a[i] < 0) { cout << "-" << abs(a[i]) ; continue; } cout << "+" << a[i] ; continue; } } if(i == 8) { if (a[i] < 0) { cout << " - " << abs(a[i]) ; continue; } cout << " + " << a[i] ; continue; } if(i == 7) { if (a[i] == 1) { cout << " + " <<"x"; continue; } else if(a[i] == -1) { cout << " - "<<"x"; continue; } if (a[i] < 0) { cout << " - " << abs(a[i]) << "x"; continue; } cout << " + " << a[i] << "x"; continue; } else if(a[i] > 0) { if (a[i] == -1 && i != 8) { cout << " - " << "x^" << 8-i; continue; } if (a[i] == 1 && i != 8) { cout <<" + "<<"x^" << 8-i; continue; } cout << " + " << a[i] << "x^" << 8-i; } else { cout << " - " <<abs(a[i]) << "x^" << 8-i ; } } if (zero) cout << 0 <<endl; else cout << endl; } } ```
×
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