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

1110 区块反转 更多...

struct  node
 

函数

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

详细描述

1110 区块反转

函数说明

◆ main()

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

在文件 pat.cpp3912 行定义.

3912 {
3913 string head;
3914 int n;
3915 int k;
3916 cin >> head >> n >> k;
3917 unordered_map<string, node> um;
3918 for(int i = 0; i < n; i++) {
3919 string address;
3920 cin >> address;
3921 um[address].address = address;
3922 cin >> um[address].data >> um[address].next;
3923 }
3924 deque<vector<node>> deq;
3925 vector<node> block;
3926 string current = head;
3927 while(current != "-1") {
3928 block.emplace_back(um[current]);
3929 if(block.size() == k) {
3930 deq.emplace_front(block);
3931 block.clear();
3932 }
3933 current = um[current].next;
3934 }
3935 if(!block.empty()) {
3936 deq.emplace_front(block);
3937 }
3938 block.clear();
3939 for(const auto &blk: deq) {
3940 for(const auto &nd: blk) {
3941 block.emplace_back(nd);
3942 }
3943 }
3944 for(int i = 0; i < block.size(); i++) {
3945 cout << block[i].address << " " << block[i].data << " " << (i + 1 < block.size() ? block[i + 1].address : "-1") << endl;
3946 }
3947 return 0;
3948 }

被这些函数引用 TEST().

◆ TEST()

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

在文件 pat_test.cpp1940 行定义.

1940 {
1941 istringstream in("00100 8 3\n"
1942 "71120 7 88666\n"
1943 "00000 4 99999\n"
1944 "00100 1 12309\n"
1945 "68237 6 71120\n"
1946 "33218 3 00000\n"
1947 "99999 5 68237\n"
1948 "88666 8 -1\n"
1949 "12309 2 33218");
1950 auto out = ostringstream();
1951 main(in, out);
1952 const auto ans = out.str();
1953 ASSERT_EQ("71120 7 88666\n"
1954 "88666 8 00000\n"
1955 "00000 4 99999\n"
1956 "99999 5 68237\n"
1957 "68237 6 00100\n"
1958 "00100 1 12309\n"
1959 "12309 2 33218\n"
1960 "33218 3 -1\n",
1961 out.str());
1962 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().