contents Problem 將一張 rgb 表示的彩色影像變成灰階影像。 套用公式 round((r + g + b)/3) 得到新的像素色彩。 Sample Input 123 3 21 2 3 4 5 6 7 8 910 11 12 13 14 15 16 17 18 Sample Output 123 3 22 2 2 5 5 5 8 8 811 11 11 14 14 14 17 17 17 Solution 123456789101112131415161718 #include <bits/stdc++.h> using namespace std;int main() { int n, m; while (scanf("%d %d", &n, &m) == 2) { printf("%d %dn", n, m); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int r, g, b, w; scanf("%d %d %d", &r, &g, &b); w = (int) round((r + g + b)/3.0); printf("%d %d %d%c", w, w, w, j == n-1 ? 'n' : ' '); } } } return 0;} 赞微海报分享
近期评论