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 }

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

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

posted @ 2019-12-21 13:12  北月真好  阅读(103)  评论(0编辑  收藏  举报