PTA 乙级 1066 图像过滤 (15分) C++
少一个for运行超时了???
1 #include<iostream> 2 #include<vector> 3 4 using namespace std; 5 6 int main() { 7 int n = 0, m = 0; 8 int a = 0, b = 0; 9 int replace = 0; 10 cin >> m >> n >> a >> b >> replace; 11 int tmp = 0; 12 for (int i = 0; i < m; ++i) { 13 for (int j = 0; j < n; ++j) { 14 cin >> tmp; 15 if (j != 0)cout << ' '; 16 if (tmp >= a && tmp <= b) printf("%03d", replace); 17 else printf("%03d", tmp); 18 } 19 cout << endl; 20 } 21 return 0; 22 }
神不神奇,意不意外
1 #include<iostream> 2 #include<vector> 3 4 using namespace std; 5 6 int main() { 7 int n = 0, m = 0; 8 int a = 0, b = 0; 9 int replace = 0; 10 cin >> m >> n >> a >> b >> replace; 11 vector<vector<int>> px(m); 12 for (int i = 0; i < m; ++i) px[i].resize(n); //创建二维数组 13 for (int i = 0; i < m; ++i) 14 for (int j = 0; j < n; ++j) 15 cin >> px[i][j]; 16 for (int i = 0; i < m; ++i) { 17 for (int j = 0; j < n; ++j) { 18 if (j != 0)cout << ' '; 19 if (px[i][j] >= a && px[i][j] <= b) printf("%03d", replace); 20 else printf("%03d", px[i][j]); 21 } 22 cout << endl; 23 } 24 25 return 0; 26 }
默默地一点点变强,细节决定成败