範例輸入:
2 6 0 8 14 0 0 0 10 0 4 0 0
範例輸出:
2 6 0 8 14 0 0 0 10 0 4 0 0- #include<bits/stdc++.h>
- using namespace std;
- string raw;
- int n;
- stringstream ss;
- vector<int> data;
- int main()
- {
- cin.tie(0);
- cin.sync_with_stdio(0);
- getline(cin, raw);
- ss<<raw;
- while(ss>>n)
- data.push_back(n);
- for(int i: data)
- cout<<i<<" ";
- cout<<endl;
- return 0;
- }
- /*
- 2 6 0 8 14 0 0 0 10 0 4 0 0
- */
複製代碼 以下為錯誤方式:- #include<bits/stdc++.h>
- using namespace std;
- int n;
- int main()
- {
- cin.tie(0);
- cin.sync_with_stdio(0);
- while(cin>>n){
- if(n==-1)
- break;
- cout<<n<<" ";
- }
- return 0;
- }
- /*
- 2 6 0 8 14 0 0 0 10 0 4 0 0
- */
複製代碼 |