1 条题解

  • 0
    @ 1997-8-31 4:45:38

    【例5.1】量身高

    解题思路

    读入身高后,将它放入 My height is 与 cm. 两段固定文本之间。

    正确性说明

    输出模板中唯一变化的是输入身高,直接替换占位部分满足要求。

    易错点

    is 后有空格,数字与 cm 之间没有空格。

    复杂度

    本题规模固定,时间 O(1),额外空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string n;
        cin >> n;
        cout << "My height is " << n << "cm.\n";
        return 0;
    }
    
    • 1