# 12394 - Easy Palindrome >author: Utin ###### tags: `array` --- ## Brief 倒著input進位比較好處理,或著可以設一個變數紀錄有無千位數 *若陣列不是全域變數請記得初始化 ## Solution 0 ```c= #include <stdio.h> int n[7]; int main() { // input for (int i = 5; i >= 0; i--) { n[i] = getchar() - '0'; if (i == 3) getchar(); } // add for (int i = 0; i < 6; i += 3) { n[i] = n[i+2] = n[i] + n[i+2]; n[i+1] *= 2; } // carry for (int i = 0; i < 6; i++) { n[i+1] += n[i] / 10; n[i] %= 10; } // output if (n[6]) printf("%d", n[6]); for (int i = 5; i >= 0; i--) { printf("%d", n[i]); if (i == 3) printf("."); } } // By Utin ``` ## Reference
×
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