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

1088 三人行 更多...

函数

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

详细描述

1088 三人行

函数说明

◆ main()

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

在文件 pat.cpp3051 行定义.

3051 {
3052 int m;
3053 int x;
3054 int y;
3055 cin >> m >> x >> y;
3056 int a;
3057 int b;
3058 int a_f;
3059 int b_f;
3060 double c_f;
3061 bool no_solution = true;
3062 for(int a = 10; a <= 99; a++) {
3063 ostringstream oss;
3064 oss << a;
3065 string str_a = oss.str();
3066 stringstream ss;
3067 for(auto it = str_a.rbegin(); it != str_a.rend(); ++it) {
3068 ss << *it;
3069 }
3070 ss >> b;
3071 const double c = static_cast<double>(b) / y;
3072 if(c * x == abs(a - b)) {
3073 no_solution = false;
3074 a_f = a;
3075 b_f = b;
3076 c_f = c;
3077 }
3078 }
3079 if(no_solution) {
3080 cout << "No Solution";
3081 return 0;
3082 }
3083 cout << a_f << ' ';
3084 if(a_f < m) {
3085 cout << "Gai ";
3086 } else if(a_f == m) {
3087 cout << "Ping ";
3088 } else {
3089 cout << "Cong ";
3090 }
3091 if(b_f < m) {
3092 cout << "Gai ";
3093 } else if(b_f == m) {
3094 cout << "Ping ";
3095 } else {
3096 cout << "Cong ";
3097 }
3098 if(c_f < m) {
3099 cout << "Gai";
3100 } else if(c_f == m) {
3101 cout << "Ping";
3102 } else {
3103 cout << "Cong";
3104 }
3105 return 0;
3106 }

被这些函数引用 TEST().

◆ TEST() [1/2]

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

在文件 pat_test.cpp1514 行定义.

1514 {
1515 istringstream in("48 3 7");
1516 auto out = ostringstream();
1517 main(in, out);
1518 const auto ans = out.str();
1519 ASSERT_EQ("48 Ping Cong Gai", out.str());
1520 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

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

在文件 pat_test.cpp1522 行定义.

1522 {
1523 istringstream in("48 11 6");
1524 auto out = ostringstream();
1525 main(in, out);
1526 const auto ans = out.str();
1527 ASSERT_EQ("No Solution", out.str());
1528 }

引用了 main().