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

1027 打印沙漏 更多...

函数

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

详细描述

1027 打印沙漏

函数说明

◆ main()

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

在文件 pat.cpp882 行定义.

882 {
883 unsigned int n;
884 char ch;
885 cin >> n >> ch;
886 int i = 1;
887 while((i + 1) * (i + 1) / 2 - 1 <= n) {
888 i += 2;
889 }
890 i -= 2;
891 for(int j = 0; j < (i + 1) / 2; ++j) {
892 for(int k = 0; k < j; k++) {
893 cout << ' ';
894 }
895 for(int k = 0; k < i - 2 * j; k++) {
896 cout << ch;
897 }
898 cout << endl;
899 }
900 for(int j = (i + 1) / 2 - 2; j >= 0; --j) {
901 for(int k = 0; k < j; k++) {
902 cout << ' ';
903 }
904 for(int k = 0; k < i - 2 * j; k++) {
905 cout << ch;
906 }
907 cout << endl;
908 }
909 cout << n - ((i + 1) * (i + 1) / 2 - 1);
910 return 0;
911 }

被这些函数引用 TEST().

◆ TEST()

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

在文件 pat_test.cpp403 行定义.

403 {
404 istringstream in("19 *");
405 auto out = ostringstream();
406 main(in, out);
407 const auto ans = out.str();
408 ASSERT_EQ("*****\n ***\n *\n ***\n*****\n2", out.str());
409 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().