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();
        }
  • 相关阅读:
    git ssh配置
    spring事务的传播行为
    springboot tomcat启动
    error while loading shared libraries: libstdc++.so.6: cannot open shared object file
    centos7安装nginx1
    linux jdk 配置
    NET CORE 3.1 UPLOAD
    vue table formrt datetime languer
    net core 3.1 swagger
    css
  • 原文地址:https://www.cnblogs.com/xkxf/p/6554818.html
Copyright © 2011-2022 走看看