11547(1/5)
#include <stdio.h> #include <math.h> int main(){ int t, n; scanf("%d", &t); for(int i = 0; i < t; i++){ scanf("%d", &n); printf("%d\n", abs((n * 567 / 9 + 7492) * 235 / 47 - 498) / 10 % 10); } return 0; } |
10018(2/5)
#include <stdio.h> int rev(int n){ int r = 0; // most important!! while(n > 0){ r = r * 10 + n % 10; n = n / 10; } return r; } void get_solved(int n){ int count, r; count = 1; r = rev(n); while(1){ n = r + n; r = rev(n); if(r == n) break; count ++; } printf("%d %d\n", count, n); } int main(){ int t, n, p, c; scanf("%d", &t); for(int i = 0; i < t; i++){ scanf("%d", &n); get_solved(n); } return 0; } |
11547就很簡單只是需要理解除法和取餘數的部分
10018就需要知道要怎麼應用除法和取餘數去做回文和回文判定了,也嘗試做了兩個function來試試看有沒有成功,結果發現有些變數若沒有宣告值一開始它不一定會=0