-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_back.cpp
More file actions
1609 lines (1609 loc) · 43.2 KB
/
main_back.cpp
File metadata and controls
1609 lines (1609 loc) · 43.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#include <iostream>
//#include <vector>
//#include "old_test/ArrayDemo/ArrayDemo.h"
//#include "old_test/standardDemo/CplusDemo.cpp"
//#include <memory>
//#include <mutex>
//
//using namespace std;
//
//void test_array_generate(){
// vector<vector<int>> res = generate(5);
//}
//
//void test_array_getRow(){
// vector<int> res = getRow(3);
// for(auto p = res.begin(); p != res.end(); p++){
// cout << *p << ",";
// }
// cout << endl;
//}
//
//void test_array_merge(){
// vector<int> v1 = {1, 2, 3, 0, 0, 0};
// vector<int> v2 = {2, 5, 6};
// merge(v1, 3, v2, 3);
// cout << endl;
// for(int i = 0; i < 6; i ++){
// cout << v1[i] << ", ";
// }
// cout << endl;
//}
//
//#include <map>
//vector<pair<string, string>> test_map(){
// map<string, string> res_map;
//// res_map.insert(pair<string, string>("f1", "v1"));
//// res_map.insert(pair<string, string>("f2", "v2"));
//// res_map.insert(pair<string, string>("f3", "v3"));
////
// vector<pair<string, string>> res_vec;
//// for(auto p = res_map.begin(); p != res_map.end(); p++){
//// res_vec.push_back(*p);
//// }
//
// map<int , string > res_int;
// res_int.insert(pair<int, string>(1,"1"));
// res_map.insert(pair<string, string>("1", "2"));
// cout << res_int[1] << endl;
// cout << res_map["1"] << endl;
//
// return res_vec;
//}
//
//void test_array_twoSum(){
// vector<int > src = {2, 7, 11, 13, 15};
// vector<int > res = twoSum(src, 15);
// for(auto it = res.begin(); it != res.end(); it++){
// cout << *it << ", ";
// }
// cout << endl;
//}
//
//void test_array_threeSum(){
// vector<int> src = {-1, 0, 2, 1, -1, -4};
// vector<int> src_1 = {0, 0, 0};
// vector<vector<int >> res = threeSum(src_1);
// cout << "[ " << endl;
// for(auto vec = res.begin(); vec != res.end(); vec++){
// cout << " [ " ;
// for(auto it = vec->begin(); it != vec->end(); it++){
// cout << *it << ",";
// }
// cout << "]," << endl;
// }
// cout << "]" << endl;
//}
//
//void test_array_fourSum(){
// vector<int> src = {1, 0, -1, 0, -2, 2};
// vector<vector<int >> res = fourSum(src, 0);
// cout << "[ " << endl;
// for(auto vec = res.begin(); vec != res.end(); vec++){
// cout << " [ " ;
// for(auto it = vec->begin(); it != vec->end(); it++){
// cout << *it << ",";
// }
// cout << "]," << endl;
// }
// cout << "]" << endl;
//}
//
//void test_array_findMin(){
// vector<int> src = {1, 2, 3};
// int res = findMin(src);
// cout << "res:" << res << endl;
//}
//
//void test_array_findmin2(){
// vector<int> src = {1, 1, 1};
// int res = findMin2(src);
// cout << "res:" << res << endl;
//}
//
//void test_array_largestRectangleArea(){
// vector<int> src = {2, 1, 5, 6, 2, 3};
//// vector<int> src = {5, 5, 1, 7, 1, 1, 5, 2, 7, 6};
//// vector<int> src = {0, 9};
// int area = largestRectangleArea(src);
// cout << "res: " << area << endl;
//}
////using namespace std;
//#include <algorithm>
//void test_algorithem(){
//// vector<int> src = {2, 1, 5, 6, 2, 3, 0};
// vector<int> src = {0, 9};
// vector<int>::iterator minimum = std::min_element(src.begin(), src.begin() + src.size());
// cout << "min:" << *minimum << endl;
//}
//void test_maximalRectangle(){
// vector<vector<char >> src;
// src.push_back({'1', '0', '1', '0', '0'});
// src.push_back({'1', '0', '1', '1', '1'});
// src.push_back({'1', '1', '1', '1', '1'});
// src.push_back({'1', '0', '0', '1', '0'});
// int res = maximalRectangle(src);
// cout << "res:" << res << endl;
//}
//
//void test_isPalindrome(){
// int src = 123;
// cout << isPalindrome(src) << endl;
//}
//
//void test_searchMatrix(){
// /*vector<vector<int >> src = {
// {1,3,5,7},
// {10,11,16,20},
// {23,30,34,50}
// };*/
// vector<vector<int>> src = {{1}};
//
// bool res = searchMatrix(src, 1);
//
// if(res)
// cout << "res : true." << endl;
// else
// cout << "res : false." << endl;
//}
//
//#include <math.h>
//
//bool test_str_contain(string src, string contain_str){
// string::size_type idx = src.find(contain_str);
// if(idx != string::npos){
// return true;
// }else{
// return false;
// }
//}
//
//void test_searchInsert(){
//// vector<int > src = {1, 3, 5, 6};
//// int target = 5;
//// int position = searchInsert(src, target);
//// cout << " position is " << position << endl;
//}
//
//string strPlus(string num1, string num2){
// if(num1.size()<num2.size()){//把num1固定为位数较大的那个数,方便后面处理
// string temp=num1;
// num1=num2;
// num2=temp;
// }
// int length1=num1.size(),length2=num2.size(),flag=0,a,b,sum;//flag是进位标记
// while(length1>0){//从低位开始把对应的位相加
// a=num1[length1-1]-'0';//获取num1当前位的数字
// if(length2>0)//如果num2还没加完(注意,num2是位数较少的)
// b=num2[length2-1]-'0';//获取num2当前位的数字
// else
// b=0;//如果num2加完了,num2对应位上就没有数来加了
// //这时我没有break,因为虽然num2没有数字来加了,但可能还有进位需要加
// sum=a+b+flag;//num1与num2对应位上的数字相加,再加上进位位
// if(sum>=10){//如果加起来大于于10,那就需要进位了
// num1[length1-1]='0'+sum%10;//计算加完之后,当前位应该是多少
// flag=1;//把进位标记置1
// }else{
// num1[length1-1]='0'+sum;//计算加完之后,当前位应该是多少
// flag=0;//把进位标记置0
// }
// length1--;//向高位移动1位
// length2--;//向高位移动1位
// }
// //如果两个数对应位都加完了,进位位是1,说明位数要增加1了
// //比如99+1,加完之后,变成了三位数100,其实就是再在前面加一位1
// if(1==flag)
// num1="1"+num1;
// return num1;
//}
//
//#include <set>
//#include <iomanip>
//
//void test_isPowerOfTwo(){
// bool res = isPowerOfTwo(2);
// if(res){
// cout << "this is true" << endl;
// }else{
// cout << "this is false" << endl;
// }
//}
//#include "old_test/TreeDemo/TreeDemo.h"
//void test_preorderTraversal(){
//
// TreeNode* n2 = new TreeNode(3);
// n2->left = NULL;
// n2->right = NULL;
// TreeNode* n1 = new TreeNode(2);
// n1->left = n2;
// n1->right = NULL;
// TreeNode* root = new TreeNode(1);
// root->left = NULL;
// root->right = n1;
//
// vector<int> res = preorderTraversal(root);
// for(auto it = res.begin(); it != res.end(); it++){
// cout << *it << "->";
// }
// cout << endl;
//}
//
//void test_connect(){
// Node* root = new Node(1);
//
// Node* n2 = new Node(2);
// Node* n3 = new Node(3);
// root->left = n2;
// root->right = n3;
//
// Node* n4 = new Node(4);
// Node* n5 = new Node(5);
// n2->left = n4;
// n2->right = n5;
//
// Node* n6 = new Node(6);
// Node* n7 = new Node(7);
// n3->left = n6;
// n3->right = n7;
//
// Node* res = connect(root);
// cout << "eqawr" << endl;
//}
//
//
//void test_path_sum(){
// TreeNode *root = new TreeNode(5);
//
// TreeNode *n1 = new TreeNode(4);
// TreeNode *n2 = new TreeNode(8);
// root->left = n1;
// root->right = n2;
//
// TreeNode *n3 = new TreeNode(11);
// TreeNode *n4 = new TreeNode(13);
// TreeNode *n5 = new TreeNode(7);
// n1->left = n3;
// n2->left = n4;
// n2->right = n5;
//
//// TreeNode *n1 = new TreeNode(4);
// vector<vector<int>> res = pathSum(root, 20);
// cout << "{" << endl;
// for(auto vec : res){
// cout << "[ ";
// for(auto i : vec){
// cout << i << ", ";
// }
// cout << "]" << endl;
// }
// cout << "}" << endl;
//}
//
//void test_flatten(){
// TreeNode *root = new TreeNode(0);
//
//// TreeNode *n1 = new TreeNode(1);
//// TreeNode *n2 = new TreeNode(2);
//// root->left = n1;
//// root->right = n2;
////
//// TreeNode *n3 = new TreeNode(3);
//// TreeNode *n4 = new TreeNode(4);
//// TreeNode *n5 = new TreeNode(5);
//// TreeNode *n6 = new TreeNode(6);
//// n1->left = n3;
//// n1->right = n4;
//// n2->left = n5;
//// n2->right = n6;
//
// flatten(root);
//}
//
//void test_c_standard(){
// int a[2][3] = {1,2,3,4,5,6};
// cout << a << endl;
//}
//
//#include <stdlib.h>
//#include <vector>
//void test_vector(){
// int num[] = {1,2,3,4,5,6,7};
//
// vector<int > vec(num, num+7);
// for (int i = 0; i < vec.size(); ++i) {
// cout << " i = " << i << ", num :" << num[i] << endl;
// }
//
// vector<int >::iterator it = find(vec.begin(), vec.end(), 5);
// if(it == vec.end()){
// cout << "not found" << endl;
// }else{
// cout << *it << " found" << endl;
//
// }
//
//}
//
//
//#include <map>
//void test_map_val_pku(){
// map<string, string> mTemp;
// mTemp["a"] = "aa";
// mTemp["b"] = "bb";
// mTemp["c"] = "cc";
// mTemp["d"] = "dd";
//
// for(auto it = mTemp.begin(); it != mTemp.end();it++){
// if(it->second == "bb"){
// mTemp.erase(it);
// }
// }
//
// for(auto it = mTemp.begin(); it != mTemp.end(); it++){
// cout << "first:" << it->first << ", second:" << it->second << endl;
// }
//
//}
//
//struct Stest{
// string name;
// void show(){
// cout << "name:" << name << endl;
// }
//};
//
//
//void print_int(const int (&i)[6]){
// cout << "cout int array" << endl;
//}
//class Tes{
//public:
// Tes(){
//
// }
// void show(){
// lock_guard<mutex> lock(t_mutex);
// cout << " this is a show method 1 " << endl;
// show2();
// }
// void show2(){
// cout << "2" << endl;
// lock_guard<mutex> lock(t_mutex);
// cout << " this is a show method 2" << endl;
// show3();
// }
// void show3(){
// cout << "3" << endl;
// lock_guard<mutex> lock(t_mutex);
// cout << " this is a show method 3" << endl;
// }
//
//private:
// string name;
// mutex t_mutex;
//};
//#include <cctype>
//void test_c_yhy_standard(){
// const char t[5] = "qwer";
// int len = sizeof(t)/sizeof(char);
// cout << "length : " << len << endl;
//
// auto test = begin(t);
// cout << *test << endl;
// cout << " ********* " << endl;
// Tes *tes = new Tes();
// shared_ptr<Tes> test_ptr(tes);
// shared_ptr<Tes> test_ptr2(tes);
// cout << test_ptr.use_count() << endl;
// cout << "asdasd" << endl;
//
//
//}
//
//
//class Scott{
//public:
// Scott()= default;
// Scott(const string &name):name_(name){
//
// }
// Scott(const string &name, const string &addr):name_(name),addr_(addr){
//
// }
// Scott(const string &name, const int &i, const int &j, const string &addr):
// name_(name),addr_(addr),index(i),row(j){
//
// }
// Scott(const int &i):row(i),index(row){
//
// }
// ~Scott(){}
// void set(const string &str){
// this->name_ = str;
// }
// string get(){
// return this->name_;
// }
// void set_addr(const string addr) const {
// addr_ = addr;
// }
// string get_addr(){
// return addr_;
// }
// void show_int(){
// cout << "index: " << index << ", row:" << row << endl;
// }
// Scott& combine(const Scott& s){
// name_ += s.name_;
// return *this;
// }
//
// void show_name(){
// cout << "name: " << name_ << endl;
// }
//
//private:
// string name_;
// int row,index;
// mutable string addr_;
//
//};
//
//
//
//#include "old_test/Other/Other.h"
//
//void test_lengthOfLongestSubstring(){
// string str = "abcabcdbd";
// int len = lengthOfLongestSubstring(str);
// cout << "result : " << len << endl;
//}
//
//
//
//#include <iterator>
//void shared_int(shared_ptr<int> p){
//
//}
//void test_itr(){
// vector<int> vec;
// auto it = back_inserter(vec);
// cout << " before operation " << endl;
// for(auto iter = vec.begin(); iter != vec.end(); iter++){
// cout << *iter << ", " ;
// }
// cout << endl;
// *it = 42;
// *it = 46;
// cout << "after operation " << endl;
// for(auto iter = vec.begin(); iter != vec.end(); iter++){
// cout << *iter << ", " ;
// }
//
// int *i(new int);
// shared_int(shared_ptr<int>(i));
// int j = *i;
// cout << "nums :" << j << endl;
//
//
//}
//
//void test_sumNumbers(){
// TreeNode* root = new TreeNode(1);
// TreeNode* n2 = new TreeNode(2);
// TreeNode* n3 = new TreeNode(3);
// TreeNode* n5 = new TreeNode(5);
// root->left = n2;
// root->right = n3;
// n2->right = n5;
//
// sumNumbers(root);
//}
//#include "old_test/DynamicPrograming/DynamicPrograming.h"
//void test_uniquePathsWithObstacles(){
// vector<vector<int>> test = {
// {0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0},
// {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
// {0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0},
// {1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,1},
// {0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0},
// {0,0,0,1,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0},
// {1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
// {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0},
// {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0},
// {0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0},
// {0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
// {1,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,1},
// {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0},
// {0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0},
// {0,1,0,0,0,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,1},
// {1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
// {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0},
// {0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,1,1},
// {0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,0,1},
// {1,1,1,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0},
// {0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1},
// {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0}
//
// };
// int res = uniquePathsWithObstacles(test);
// cout << "res : " << res << endl;
//}
//
//
//void test_maxProfit3(){
// vector<int> prices = {6,1,3,2,4,7};
// int max_pro = maxProfit3(prices);
// cout << max_pro << endl;
//}
//
//void test_minPathSum(){
// vector<vector<int>> test = {
// {1,3,1},
// {1,5,1},
// {4,2,1}
// };
// int res = minPathSum(test);
// cout << "res : " << res << endl;
//}
//
//void test_numSquars(){
// int num = 12;
// int res = numSquars(num);
// cout << "res:" << res << endl;
//}
//
//extern int test_yhy;
//extern void test_yhy_m();
//
//extern int name_yhy;
//extern void name_yhy_m();
//
//#include "old_test/JZOffer/File1.h"
//void test_offer(){
// JZListNode *head = new JZListNode(1);
// JZListNode *p1 = new JZListNode(2);
// JZListNode *p2 = new JZListNode(3);
// JZListNode *p3 = new JZListNode(4);
// head->next = p1;
// p1->next = p2;
// p2->next = p3;
// vector<int> res = printListFromTailToHead(head);
//
// for(auto it = res.begin(); it != res.end(); it++){
// cout << *it << "->" ;
// }
//}
//
//#include "old_test/BackTracing/BackTracing.h"
//void test_combinationSum(){
//
// vector<int> can = {2, 3, 5};
// std::vector<std::vector<int>> res = combinationSum(can, 8);
// for(int i = 0; i < res.size(); i++){
// for(int j=0; j < res[i].size(); j++){
// cout << res[i][j] << ", ";
// }
// cout << endl;
// }
//}
//
//class A{
//private:
// string name;
//public:
// A()= default;
// A(string n):name(n){}
// ~A(){}
// void change_and_show() {
// name = "wahaha";
// cout << "name:" << (*this).name << endl;
// }
//};
//
//#include <queue>
//#include <algorithm>
//
//void test_combinationSum2(){
// vector<int> can = {2, 2, 1, 2, 5};
// vector<vector<int>> res = combinationSum2(can, 5);
// for(int i = 0; i < res.size(); i++){
// for(int j=0; j < res[i].size(); j++){
// cout << res[i][j] << ", ";
// }
// cout << endl;
// }
//}
//
//#include "old_test/GreedyDemo/GreedyDemo.h"
//
//void test_canCompleteCircuit(){
// vector<int> gas = {1, 2, 3, 4, 5};
// vector<int> cost = {3, 4, 5, 1, 2};
// int res = canCompleteCircuit(gas, cost);
// cout << "res:" << res << endl;
//}
//
//void test_set(){
// set<string> str_set;
// str_set.emplace("java");
// str_set.emplace("avaj");
// str_set.emplace("dvaj");
// str_set.emplace("bava");
//
// for(auto it : str_set){
// cout << "," << it;
// }
// cout << "." << endl;
//}
//
//#include "old_test/standardDemo/CPPStanderDemo.h"
//
//bool comp (const Student &left, const Student &right){
// cout << "comp method" << endl;
// if(left.name_ != right.name_){
// return left.name_ < right.name_;
// }else{
// return left.age_ < right.age_;
// }
//}
//
//void test_student(){
//// set<Student, decltype(comp)*> s(comp);
//// set<Student, Comp> s;
//// pair<set<Student>::iterator, bool > res = s.emplace(Student("Janney", 23));
//// if(res.second){
//// cout << "successful." << endl;
//// }
//// s.emplace(Student("Danney", 22));
//// s.emplace(Student("LiMing", 20));
//// s.emplace(Student("LiMing", 18));
//// s.emplace(Student("于海洋", 18));
//// s.emplace(Student("黎明", 18));
//// s.emplace(Student("哈哈", 18));
//// s.emplace(Student("梵蒂冈", 18));
////
//// s.insert(res.first,Student("Yuhy", 26));
////
//// for(auto it : s){
//// cout << it.show() << endl;
////
//// }
//
// set<int> sInt;
// //元素添加
// //1、返回pair对象,second表示是否添加成功
// pair<set<int>::iterator, bool > isSu = sInt.insert(5);
// if(isSu.second){
// cout << "successful!" << endl;
// }
// //2、在iterator前插入元素 insert(&pos, value),返回新元素的位置
// sInt.insert(isSu.first,9);
// //3、添加区间,将区间[&first, &last)区间内的元素添加到set中
// int array[] = {4, 10, 6};
// sInt.insert(array, array+3);
//
// for(auto it : sInt){
// cout << it << ", ";
// }
//
// //元素删除
// //1、erase(value),返回移除元素的个数
//// auto num = sInt.erase(6);
//// cout << "移除元素个数:" << num << endl;
//// //2、erase(&pos),移除pos上的元素,无返回值
//// auto iter = sInt.begin();
//// sInt.erase(iter);
//// for(auto it : sInt){
//// cout << it << ", ";
//// }
//// //3、erase(&first, &last),移除[&first, &last)区间内的元素
////
////// sInt.erase(sInt.begin(), sInt.end());
//// cout << endl << "after [fir, last) : " << endl;
//// for(auto it : sInt){
//// cout << it << ", ";
//// }
//// //4、移除所有元素
//// sInt.clear();
//// cout << endl << "after clear : " << endl;
//// for(auto it : sInt){
//// cout << it << ", ";
//// }
//
// //查找
// //1、count(value),返回value的个数
// cout << sInt.count(10) << endl;
// //2、iterator find(value),返回value的位置,如果找不到,则返回end()
// auto res_find_f = sInt.find(10);
// if(res_find_f == sInt.end()){
// cout << "未找到" << endl;
// }else{
// cout << "已找到" << endl;
//
// }
// auto res_find_s = sInt.find(20);
// if(res_find_s == sInt.end()){
// cout << "未找到" << endl;
// }else{
// cout << "已找到" << endl;
//
// }
//
//
//
//
//
//
//
//
//}
//
//bool cmp_value(const pair<Student, string>& a, const pair<Student, string>& b) {
// return b.second < a.second;
//}
//
//void test_map_learn(){
// map<int, string> m_str;
// pair<map<int, string>::iterator, bool> is_suc;
// //map的插入有三种方式
// //1、insert(pair<>)
// is_suc = m_str.insert(pair<int, string>(2, "yuhy"));
// //可以用is_suc判断是否插入成功
// if(is_suc.second){
// cout << "successful" << endl;
// }else{
// cout << "failed" << endl;
// }
// //2、insert (value_type)
// m_str.insert(map<int, string>::value_type(5, "scott"));
// //3、用数组方式插入数据
// m_str[1] = "LiMing";
//
//
// //遍历方式四种:
// //1、for each
// for(auto it : m_str){
// cout << "key:" << it.first << ", value:" << it.second << endl;
// }
// cout << "-------" << endl;
// //2、前向迭代器
// for(auto it = m_str.begin(); it != m_str.end(); it++){
// cout << "key:" << it->first << ", value:" << it->second << endl;
// }
// cout << "-------" << endl;
// //3、反向迭代器
// for(auto it = m_str.rbegin(); it != m_str.rend(); it++){
// cout << "key:" << it->first << ", value:" << it->second << endl;
// }
// cout << "-------" << endl;
// //4、数组遍历方式
//// for(int i=0; i<m_str.size(); i++){
//// cout << "value:" << m_str[i] << endl;
//// }
//
// //查找,两种
// //1、count,查询关键字是否出现,无法判定其位置,返回值0或者1,1表示存在
// cout << "5 是否出现 :" ;
// if(m_str.count(5) == 1){
// cout << "是";
// }else{
// cout << "否";
// }
// cout << endl;
// //2、find,返回值是迭代器,如果不存在则返回end()
// map<int, string>::iterator res_find = m_str.find(5);
// if(res_find == m_str.end()){
// cout << "yuhy 不存在" << endl;
// }else{
// cout << "yuhy key:" << res_find->first << ", value:" << res_find->second << endl;
// }
//
// //删除
// //1、erase(k),删除键为k的元素,并返回删除的个数
// cout << "--- 删除 ----" << endl;
// for(auto it : m_str){
// cout << "key:" << it.first << ", value:" << it.second << endl;
// }
// cout << "-------" << endl;
// map<int, string>::size_type res_erase = m_str.erase(5);
// cout << "num of erase:" << res_erase << endl;
// for(auto it : m_str){
// cout << "key:" << it.first << ", value:" << it.second << endl;
// }
// cout << "-------" << endl;
// //2、erase(it),删除迭代器it指向的元素
// m_str.erase(m_str.find(1));
// for(auto it : m_str){
// cout << "key:" << it.first << ", value:" << it.second << endl;
// }
// cout << "-------" << endl;
//
// //3、erase(it_f, it_e),删除一段范围内的元素
// m_str.erase(m_str.begin(), m_str.end());
// for(auto it : m_str){
// cout << "key:" << it.first << ", value:" << it.second << endl;
// }
// cout << "-------" << endl;
//
//
// map<Student, string, decltype(comp)*> m_stu(comp);
// m_stu.insert(pair<Student, string>(Student("yyy", 20), "yyy"));
// m_stu.insert(pair<Student, string>(Student("aaa", 20), "aaa"));
// m_stu.insert(pair<Student, string>(Student("yyy", 18), "yyy"));
// cout << "--- 排序 ---" << endl;
// for(auto it : m_stu){
// cout << "key-name:" << it.first.name_ << ", key-age:" << it.first.age_ << ", value:" << it.second << endl;
// }
//
// vector<pair<Student, string>> vec(m_stu.begin(), m_stu.end());
// sort(vec.begin(), vec.end(), cmp_value);
// for(auto it : vec){
// cout << "key-name:" << it.first.name_ << ", key-age:" << it.first.age_ << ", value:" << it.second << endl;
// }
//
//}
//
//void test_vect_learn(){
// vector<int> vec = {1,2,3,4,5,6,7,8,9,10};
// //三种遍历方式
// //1、下标
// for(int i=0; i<vec.size(); i++){
// cout << vec[i] << ", ";
// }
// cout << endl << "---------" << endl;
// //2、迭代器
// for(vector<int>::iterator it = vec.begin(); it != vec.end(); it++){
// cout << *it << ", ";
// }
// cout << endl << "---------" << endl;
// //3、for each
// for(int temp : vec){
// cout << temp << ", ";
// }
//
//}
//
//#include <sstream>
//
//void test_string_learn(){
//// string str = "Hello, I am LiMing.";
//// const char* cstr = str.c_str();
//// cout << cstr << endl;
//// str = "Hello, I am Jenny";
//// cout << cstr << endl;
//
//// char *cstr = new char[25];
//// string str = "Hello, I am LiMing.";
//// strncpy(cstr, str.c_str(), str.size());
//// cout << cstr << ", " << str.size() << endl;
//// str = "Hello, I am Jenny";
//// cout << cstr << endl;
//// string str = "Hello, I am LiMing.";
//// size_t length;
//// char buf[8];
//// string str("Hello, I am LiMing.");
//// cout << str << endl;
////
//// length = str.copy(buf, 7, 3);
//// cout << "length:" << length << endl;
//// buf[length] = '\0';
//// cout << "str.copy(buf, 7, 5), buf contains:" << buf << endl;
//// cout << "buf len :" << strlen(buf) << endl;
////
////
//// length = str.copy(buf, str.size(), 3);
//// cout << "length:" << length << endl;
//// buf[length] = '\0';
//// cout << "str.copy(buf, str.size(), 5), buf contains:" << buf << endl;
//// cout << "buf len :" << strlen(buf) << endl;
// //int 转 string
// int a_1 = 99;
// string str_1;
// stringstream ss;
// ss << a_1;
// ss >> str_1;
// cout << "a_1:" << a_1 << endl;
// cout << "str_1:" << str_1 << endl;
// //string 转 int
// int a_2;
// string str_2 = "12345";
// ss.clear();//清除ss中的数据
// ss << str_2;
// ss >> a_2;
// cout << "str_2:" << str_2 << endl;
// cout << "a_2:" << a_2 << endl;
//
// //string 转 int
// string str_3 = "54321";
// int a_3 = stoi(str_3);
// cout << "str_3:" << str_3 << endl;
// cout << "a_3:" << a_3 << endl;
//
// //int 转 string
// int a_4 = 54321;
// string str_4 = to_string(a_4);
// cout << "a_4:" << a_4 << endl;
// cout << "str_3:" << str_3 << endl;
//
// double res = 0;
//
//
//
//
//
//}
//
//
//struct TestListNode {
// int val;
// struct TestListNode *next;
// TestListNode(int x) :
// val(x), next(NULL) {
// }
//};
//
//TestListNode* reverse_node(TestListNode* pHead){
// if(pHead == NULL){
// return NULL;
// }
// auto pre = pHead;
// pHead = pHead->next;
// pre->next = NULL;
// while(pHead){
// auto temp = pHead;
// pHead = pHead->next;
// temp->next = pre;
// pre = temp;
// }
// return pre;
//
//}
//
//void test_reverse(){
// TestListNode* root = new TestListNode(0);
// TestListNode* n1 = new TestListNode(1);
// TestListNode* n2 = new TestListNode(2);
// TestListNode* n3 = new TestListNode(3);
// TestListNode* n4 = new TestListNode(4);
// TestListNode* n5 = new TestListNode(5);
// root->next = n1;
// n1->next = n2;
// n2->next = n3;
// n3->next = n4;
// n4->next = n5;
// n5->next = NULL;
//
// auto res = reverse_node(root);
//
// while(res){
// cout << res->val << "->";
// res = res->next;
// }
// cout << endl;
//
//
//
//}
//
//ListNode* Merge(ListNode* pHead1, ListNode* pHead2)
//{
// ListNode* newHead = new ListNode(0);
// auto last = newHead;
// while(pHead1 && pHead2){
// if(pHead1->val < pHead2->val){
// auto temp = pHead1;
// pHead1 = pHead1->next;
// last->next = temp;
//
// }else{
// auto temp = pHead2;