zoukankan      html  css  js  c++  java
  • c++ 跳转语句块

    p170~p172:
    跳转语句:
    1、break:对while for switch有效!
    2、continue:中断当前迭代,但是循环还要继续。因此while for有效,对switch无效!
    3、goto:不要使用!

    练习:

    5.20

    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        /*
                输入一组字符串,例如a b c d e e输出为e
            若输入为a b c d e f输出为“没有单词重复出现~”
         */
        string word, lastw;
        cin >> lastw; // 初始化
        bool has_sameword = false;
        while (cin >> word) {
            if (word == lastw) {
                cout << word << endl;
                has_sameword = true;
                break;
            } else {
           lastw = word;
         } }
    if (!has_sameword) { cout << "没有单词重复出现~”" << endl; } return 0; }

    5.21

    #include <iostream>
    #include <string>
    using namespace std;
    bool capital_begin(string word) {
        if (word[0] >= 'A' && word[0] <= 'Z') {
            return true;
        }
        return false;
    }
    int main()
    {
        /*
                输入一组字符串,例如a b c d e e输出为“没有以大写字母开头的单词重复出现~”
            若输入为a b c d e F F j k则输出为F,这样的话增加一个条件就好了。
         */
        string word, lastw;
        cin >> lastw; // 初始化
        bool has_sameword = false;
        bool lastW = false;
        while (cin >> word) {
            if (word == lastw && capital_begin(word)) {
                cout << word << endl;
                has_sameword = true;
                break;
            } else {
                lastw = word;
            }
        }
        if (!has_sameword) {
            cout << "没有以大写字母开头的单词重复出现~" << endl;
        }
        return 0;
    }

    5.22

        int sz = -1;
        while (sz <= 0) {
            sz = get_size();
        }
  • 相关阅读:
    SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSAS 系列
    微软BI 之SSRS 系列
    微软BI 之SSRS 系列
    配置 SQL Server Email 发送以及 Job 的 Notification通知功能
  • 原文地址:https://www.cnblogs.com/xkxf/p/6554818.html
Copyright © 2011-2022 走看看