c++primer 6.15while循环习题!

#include<iostream>
#include<vector>
using namespace std;

int main() {

    vector<int> v1;

    vector<int> v2;


    cout << "please press into vec1's elements" << endl;
    int a = 0;
    bool flag1 = true;
    while (flag1)
    {
        if (cin >> a) {
            v1.push_back(a);
        }
        else {
            flag1 = false;
            cout << "vec1 is done" << endl;
        }
    }

    cin.clear();                          //清理状态
    //cin.ignore();                       //忽略最后输入的字符

    cout << "please press into vec2's elements" << endl;
    bool flag2 = true;
    while (flag2)
    {
        if (cin >> a) {
            v2.push_back(a);
        }
        else {
            flag2 = false;
            cout << "vec2 is done" << endl;
        }
    }

    cout << "start comparing......" << endl;

    vector<int> *vb = 0;
    vector<int> *vs = 0;
    if (v1.size() >= v2.size()) {
        vb = &v1;
        vs = &v2;
    }
    else {
        vb = &v2;
        vs = &v1;
    }

    bool flag = true;
    for (vector<int>::iterator itr1 = (*vb).begin(), itr2 = (*vs).begin(); itr2 != (*vs).end(); ++itr1, ++itr2) {
        if (*itr1 != *itr2) {
            cout << "nnnnnnnnnnnnnnnnoooooooooo!"<<endl;
            flag = false;
            break;
        }
    }

    if (flag) {
        cout << "yes it is!" << endl;
    }
    else {
        cout << "too bad" << endl;
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++ Primer习题集(第五版) , 带目录完整版。 --------------------------------------------------------------------------- 目录 第1章............................................................ 1 练习1.1 练 习1.25 第2 章变量和基本类型................................................. 12 练习2.1 练 习2.42 第3 章字符串、向量和数组..............................................37 练习3.1 练 习3.45 第4 章表达式......................................................... 80 练习4.1 练 习4.38 第5 章语句........................................................... 99 练习5.1 练 习5.25 第6 章函数.......................................................... 120 练习6.1 练 习6.56 m m m ...................................................................... 152 练习7.1 练 习7.58 第8 章1 0库..........................................................183 练习8.1 练 习8.14 第9 章顺序容器...................................................... 193 练习9.1 练 习9.52 第10章泛型算法..................................................... 234 练习10.1 练 习10.42 目录 ◄ v 第11章关联容器..................................................... 273 练习11.1 练 习11.38 第12章动态内存..................................................... 297 练习12.1 练 习12.33 第13章拷贝控制..................................................... 331 练习13.1 练 习13.58 第14章重载运算与类型转换............................................368 练习14.1 练 习14.53 第15章面向对象程序设计..............................................399 练习15.1 练 习15.42 第16章模板与泛型编程............................................... 424 练习16.1 练 习16.67 第17章标准库特殊设施............................................... 458 练习17.1 练 习17.39 第18章用于大型程序的工具............................................483 练习18.1 练 习18.30 第19章特殊工具与技术............................................... 502 练习19.1 练 习19.26

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值