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

  1. 见面与问候
更多...

函数

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

详细描述

  1. 见面与问候

函数说明

◆ main()

int acwing::acwing1995::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp6901 行定义.

6901 {
6902 int b;
6903 int e;
6904 cin >> b >> e;
6905 vector<int> pos_b;
6906 vector<int> pos_e;
6907 pos_b.push_back(0);
6908 pos_e.push_back(0);
6909 while(b-- != 0) {
6910 char dir;
6911 int dist;
6912 cin >> dist >> dir;
6913 if(dir == 'L') {
6914 for(int i = 0; i < dist; i++) {
6915 pos_b.push_back(pos_b.back() - 1);
6916 }
6917 } else {
6918 for(int i = 0; i < dist; i++) {
6919 pos_b.push_back(pos_b.back() + 1);
6920 }
6921 }
6922 }
6923 while(e-- != 0) {
6924 char dir;
6925 int dist;
6926 cin >> dist >> dir;
6927 if(dir == 'L') {
6928 for(int i = 0; i < dist; i++) {
6929 pos_e.push_back(pos_e.back() - 1);
6930 }
6931 } else {
6932 for(int i = 0; i < dist; i++) {
6933 pos_e.push_back(pos_e.back() + 1);
6934 }
6935 }
6936 }
6937 const int t = max(pos_e.size(), pos_b.size());
6938 int ans = 0;
6939 bool flag = true;
6940 for(int i = 0; i < t; i++) {
6941 const int pe = i < pos_e.size() ? pos_e[i] : pos_e.back();
6942 const int pb = i < pos_b.size() ? pos_b[i] : pos_b.back();
6943 if(pe == pb) {
6944 if(!flag) {
6945 ans++;
6946 }
6947 flag = true;
6948 } else {
6949 flag = false;
6950 }
6951 }
6952 cout << ans;
6953 return 0;
6954 }

被这些函数引用 TEST().

◆ TEST()

acwing::acwing1995::TEST ( acwing1995  ,
case1   
)

在文件 acwing_test.cpp3244 行定义.

3244 {
3245 istringstream in("4 5\n"
3246 "3 L\n"
3247 "5 R\n"
3248 "1 L\n"
3249 "2 R\n"
3250 "4 R\n"
3251 "1 L\n"
3252 "3 L\n"
3253 "4 R\n"
3254 "2 L");
3255 auto out = ostringstream();
3256 main(in, out);
3257 const auto ans = out.str();
3258 ASSERT_EQ("3", ans);
3259 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().