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

1019 数字黑洞 更多...

函数

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

详细描述

1019 数字黑洞

函数说明

◆ main()

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

在文件 pat.cpp659 行定义.

659 {
660 string num;
661 cin >> num;
662 int a = 0;
663 int b = 0;
664 while(num.length() < 4) {
665 num = num + '0';
666 }
667 if(num == "0000") {
668 cout << "0000 - 0000 = 0000";
669 return 0;
670 }
671 while(num != "0000" && a - b != 6174) {
672 stringstream ssa;
673 stringstream ssb;
674 stringstream ss;
675 sort(num.rbegin(), num.rend());
676 ssa << num;
677 ssa >> a;
678 sort(num.begin(), num.end());
679 ssb << num;
680 ssb >> b;
681 ss << setw(4) << right << setfill('0') << a - b;
682 num = "";
683 ss >> num;
684 cout << setw(4) << right << setfill('0') << a << " - " << setw(4) << right << setfill('0') << b << " = " << setw(4) << right << setfill('0') << a - b << endl;
685 }
686 return 0;
687 }

引用了 acwing::acwing1929::right.

被这些函数引用 TEST().

◆ TEST() [1/2]

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

在文件 pat_test.cpp284 行定义.

284 {
285 istringstream in("6767");
286 auto out = ostringstream();
287 main(in, out);
288 const auto ans = out.str();
289 ASSERT_EQ("7766 - 6677 = 1089\n9810 - 0189 = 9621\n9621 - 1269 = 8352\n8532 - 2358 = 6174\n", ans);
290 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

pat::b::b1019::TEST ( b1019  ,
case2   
)

在文件 pat_test.cpp292 行定义.

292 {
293 istringstream in("2222");
294 auto out = ostringstream();
295 main(in, out);
296 const auto ans = out.str();
297 ASSERT_EQ("2222 - 2222 = 0000\n", out.str());
298 }

引用了 main().