码迷,mamicode.com
首页 > 编程语言 > 详细

c++ primer 3.5.5节练习答案

时间:2017-07-27 20:20:46      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:amp   []   logs   while   答案   c++   tor   prim   sys   

练习3.41

1 int main()
2 {
3     int a[] = { 0,1,2,3,4,5 };
4     vector<int> a1(begin(a) + 1, begin(a) + 5);
5     for (auto c : a1)
6         cout << c << endl;
7     system("pause");
8     return 0;
9 }

练习3.42

 1 int main()
 2 {
 3     int num;
 4     vector<int> a1;
 5     while (cin >> num)
 6         a1.push_back(num);
 7     int a[10];
 8     int *beg = begin(a);
 9     int *last = end(a);
10     auto beg1 = a1.cbegin();
11     auto last1 = a1.cend();
12     if (a1.size() >= 10)
13     {
14         while (beg != last)
15         {
16             *beg = *beg1;
17             beg++;
18             beg1++;
19         }
20     }
21     else
22     {
23         while (beg1 != last1)
24         {
25             *beg = *beg1;
26             beg++;
27             beg1++;
28             while (beg1 == last1 && beg != last)
29             {
30                 *beg = 0;
31                 beg++;
32             }
33         }
34     }
35     for (auto c : a)
36         cout << c << endl;
37     system("pause");
38     return 0;
39 }

 

c++ primer 3.5.5节练习答案

标签:amp   []   logs   while   答案   c++   tor   prim   sys   

原文地址:http://www.cnblogs.com/wuyinfenghappy/p/7246447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!