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

  1. C翻转
更多...

函数

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

详细描述

  1. C翻转

函数说明

◆ main()

int acwing::acwing3535::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing408.cpp1554 行定义.

1554 {
1555 int dir, len, x, y;
1556
1557 vector<vector<int>> mat = vector<vector<int>>(6, vector<int>(6, 0));
1558 for(int i = 1; i <= 5; i++) {
1559 for(int j = 1; j <= 5; j++) {
1560 cin >> mat[i][j];
1561 }
1562 }
1563 vector<vector<int>> ret = mat;
1564 cin >> dir >> len >> x >> y;
1565 int transform[2][2][2] = {
1566 {{0, 1},
1567 {-1, 0}},
1568 {{0, -1},
1569 {1, 0}},
1570 };
1571 dir--;
1572 for(int i = x; i < x + len; i++) {
1573 for(int j = y; j < y + len; j++) {
1574 int i0 = i - x + 1;
1575 int j0 = j - y + 1;
1576 int i2 = transform[dir][0][0] * i0 + transform[dir][0][1] * j0;
1577 int j2 = transform[dir][1][0] * i0 + transform[dir][1][1] * j0;
1578 if(dir == 0) {
1579 j2 += len + 1;
1580 } else {
1581 i2 += len + 1;
1582 }
1583 i2 += x - 1;
1584 j2 += y - 1;
1585 ret[i2][j2] = mat[i][j];
1586 }
1587 }
1588 for(int i = 1; i <= 5; i++) {
1589 for(int j = 1; j <= 5; j++) {
1590 cout << ret[i][j] << ' ';
1591 }
1592 cout << endl;
1593 }
1594 return 0;
1595 }

被这些函数引用 TEST().

◆ TEST() [1/2]

acwing::acwing3535::TEST ( acwing3535  ,
case1   
)

在文件 acwing408_test.cpp1812 行定义.

1812 {
1813 istringstream in("1 2 3 4 5\n"
1814 "6 7 8 9 10\n"
1815 "11 12 13 14 15\n"
1816 "16 17 18 19 20\n"
1817 "21 22 23 24 25\n"
1818 "1 3 1 1");
1819 auto out = ostringstream();
1820 main(in, out);
1821 const auto ans = out.str();
1822 ASSERT_EQ("11 6 1 4 5 \n"
1823 "12 7 2 9 10 \n"
1824 "13 8 3 14 15 \n"
1825 "16 17 18 19 20 \n"
1826 "21 22 23 24 25 \n",
1827 ans);
1828 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

acwing::acwing3535::TEST ( acwing3535  ,
case2   
)

在文件 acwing408_test.cpp1830 行定义.

1830 {
1831 istringstream in("19 5 7 16 12\n"
1832 "17 9 6 9 11\n"
1833 "9 19 14 10 8\n"
1834 "11 12 20 2 13\n"
1835 "16 10 7 2 10\n"
1836 "1 2 3 4");
1837 auto out = ostringstream();
1838 main(in, out);
1839 const auto ans = out.str();
1840 ASSERT_EQ("19 5 7 16 12 \n"
1841 "17 9 6 9 11 \n"
1842 "9 19 14 2 10 \n"
1843 "11 12 20 13 8 \n"
1844 "16 10 7 2 10 \n",
1845 ans);
1846 }

引用了 main().