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

1048 数字加密 更多...

函数

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

详细描述

1048 数字加密

函数说明

◆ main()

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

在文件 pat.cpp1578 行定义.

1578 {
1579 string a;
1580 string b;
1581 cin >> a >> b;
1582 vector<char> ans;
1583 int i = 1;
1584 for(; i <= max(b.length(), a.length()); ++i) {
1585 const int bi = b.length() >= i ? b[b.length() - i] - '0' : 0;
1586 const int ai = a.length() >= i ? a[a.length() - i] - '0' : 0;
1587 if(i % 2 != 0) {
1588 char ret = (ai + bi) % 13;
1589 switch(ret) {
1590 case 10:
1591 ret = 'J';
1592 break;
1593 case 11:
1594 ret = 'Q';
1595 break;
1596 case 12:
1597 ret = 'K';
1598 break;
1599 default:
1600 ret += '0';
1601 break;
1602 }
1603 ans.push_back(ret);
1604 } else {
1605 int ret = bi - ai;
1606 if(ret < 0) {
1607 ret += 10;
1608 }
1609 ans.push_back(ret + '0');
1610 }
1611 }
1612 for(auto it = ans.rbegin(); it != ans.rend(); ++it) {
1613 cout << *it;
1614 }
1615 return 0;
1616 }

被这些函数引用 TEST().

◆ TEST()

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

在文件 pat_test.cpp745 行定义.

745 {
746 istringstream in("1234567 368782971");
747 auto out = ostringstream();
748 main(in, out);
749 const auto ans = out.str();
750 ASSERT_EQ("3695Q8118", out.str());
751 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().