zoukankan      html  css  js  c++  java
  • Q1094

    一,看题

    1,字符串确实是我的弱项。

    2,

    二,看题解

     1 #include<iostream>
     2 #include<string>
     3 using namespace std;
     4 int main(){
     5     string a[100];
     6     string s;
     7     int x;
     8     cin>>x;
     9     cin.get();//这一步很关键。
    10     for(int i=0;i<x;i++)
    11     {
    12         getline(cin,a[i]);
    13         cout<<a[i]<<endl<<endl;
    14     }
    15     while(cin>>s)
    16     {
    17         cout<<s<<endl<<endl;
    18     }
    19     
    20     
    21 }

    1,但是我对于cin.get()这步还是感觉很奇怪。

    这块的用法确实挺奇怪的,显然这块我不会。

    2,说实话getline()的用法我也不明确。

    然后肯定得改进一下

     1 #include<iostream>
     2 #include<string>
     3 using namespace std;
     4 int main(){
     5     string a[100];
     6     string s;
     7     int x;
     8     cin>>x;
     9 //    cin.get();
    10     for(int i=0;i<x+1;i++)
    11     {
    12         getline(cin,a[i]);
    13         cout<<a[i]<<endl<<endl;
    14     }
    15     while(cin>>s)
    16     {
    17         cout<<s<<endl<<endl;
    18     }
    19     
    20     
    21 
    22 }

    两个程序的答案大致可以,但是你的第二个过不了由于上面多了两行空格;

    你还是再思考思考这题目吧。

  • 相关阅读:
    连接ESP32失败:等待包头 #226超时
    题王网
    高可用架构模式——CAP
    高性能负载均衡
    单服务器高性能模式
    虚拟支付
    高性能架构设计——数据库篇
    MySQL
    shell 命令: MD5
    HTTPS
  • 原文地址:https://www.cnblogs.com/beiyueya/p/12076647.html
Copyright © 2011-2022 走看看