PAT c++出现两个段错误是什么原因?
PAT乙级1010#include<iostream>#include<string>#include<vector>#include<functional>#inclu...
PAT 乙级 1010
#include<iostream>
#include<string>
#include<vector>
#include <functional>
#include <iterator>
#include <algorithm>
#include<stdio.h>
#include<cmath>
#include<ctime>
using namespace std;
int main()
{
vector<int > vec;
int i;
cin>>i;
while(cin.get()!='\n')
{
vec.push_back(i);
cin>>i;
}
vec.push_back(i);
if(vec.size()%2!=0)
vec.push_back(0);
int i1,i2;
auto it=vec.begin();
vector<int> vec1;
while(it!=vec.end())
{
i1=*it++;
i2=*it++;
if(i2==0)
break;
vec1.push_back(i1*i2);
vec1.push_back(i2-1);
}
copy(vec1.begin(),vec1.end()-1,ostream_iterator<int,char>(cout," "));
cout<<*(vec1.end()-1);
system("pause");
} 展开
#include<iostream>
#include<string>
#include<vector>
#include <functional>
#include <iterator>
#include <algorithm>
#include<stdio.h>
#include<cmath>
#include<ctime>
using namespace std;
int main()
{
vector<int > vec;
int i;
cin>>i;
while(cin.get()!='\n')
{
vec.push_back(i);
cin>>i;
}
vec.push_back(i);
if(vec.size()%2!=0)
vec.push_back(0);
int i1,i2;
auto it=vec.begin();
vector<int> vec1;
while(it!=vec.end())
{
i1=*it++;
i2=*it++;
if(i2==0)
break;
vec1.push_back(i1*i2);
vec1.push_back(i2-1);
}
copy(vec1.begin(),vec1.end()-1,ostream_iterator<int,char>(cout," "));
cout<<*(vec1.end()-1);
system("pause");
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询