problemscpp
A collection of my answers to algorithm problems in c++.
函数
pat::b::b1097 命名空间参考

1097 矩阵行平移 更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1097, case1)
 

详细描述

1097 矩阵行平移

函数说明

◆ main()

int pat::b::b1097::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp3461 行定义.

3461 {
3462 int n;
3463 int k;
3464 int x;
3465 cin >> n >> k >> x;
3466 vector grid(n, vector<int>(n));
3467 for(int i = 0; i < n; i++) {
3468 for(int j = 0; j < n; j++) {
3469 cin >> grid[i][j];
3470 }
3471 }
3472 int indent = 1;
3473 for(int i = 0; i < n; i += 2) {
3474 for(int j = n - 1; j >= 0; j--) {
3475 grid[i][j] = j - indent >= 0 ? grid[i][j - indent] : x;
3476 }
3477 indent++;
3478 if(indent == k + 1) {
3479 indent = 1;
3480 }
3481 }
3482 for(int j = 0; j < n; j++) {
3483 int sum = 0;
3484 for(int i = 0; i < n; i++) {
3485 sum += grid[i][j];
3486 }
3487 cout << sum;
3488 if(j != n - 1) {
3489 cout << ' ';
3490 }
3491 }
3492 return 0;
3493 }

被这些函数引用 TEST().

◆ TEST()

pat::b::b1097::TEST ( b1097  ,
case1   
)

在文件 pat_test.cpp1693 行定义.

1693 {
1694 istringstream in("7 2 99\n"
1695 "11 87 23 67 20 75 89\n"
1696 "37 94 27 91 63 50 11\n"
1697 "44 38 50 26 40 26 24\n"
1698 "73 85 63 28 62 18 68\n"
1699 "15 83 27 97 88 25 43\n"
1700 "23 78 98 20 30 81 99\n"
1701 "77 36 48 59 25 34 22");
1702 auto out = ostringstream();
1703 main(in, out);
1704 const auto ans = out.str();
1705 ASSERT_EQ("529 481 479 263 417 342 343", out.str());
1706 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().