做 PAT 经常段错误
刷PAT题的时候经常出现段错误啊,不知道哪里错了程序代码:
[code][code] #include<iostream> #include<vector> #include<stdio.h> using std::vector; int main() { int N,temp; std::cin>>N; vector<int> input; vector<int> clas[5][1]; for(int i=0;i<N;i++) { std::cin>>temp; input.push_back(temp); } auto iterbeg=input.begin(); auto iterend=input.end(); for(;iterbeg!=iterend;iterbeg++) { temp=(*iterbeg)%5; switch(temp) { case 0 : (*clas[0]).push_back(*iterbeg);break; case 1 :(*clas[1]).push_back(*iterbeg);break; // case 2 :(*clas[2]).push_back(*iterbeg);break; case 3 :(*clas[3]).push_back(*iterbeg);break; case 4 :(*clas[4]).push_back(*iterbeg);break; } } int sum=0; iterbeg=(clas[0]->begin()); iterend=(clas[0]->end()); for(;iterbeg!=iterend;iterbeg++) if((*iterbeg)%2==0) sum=sum+(*iterbeg); if(sum==0) std::cout<<"N "; else std::cout<<sum<<" "; int a=1; sum=0; iterbeg=(clas[1]->begin()); iterend=(clas[1]->end()); for(;iterbeg!=iterend;iterbeg++) { sum=sum+(*iterbeg)*a; a=a*(-1); } if(sum==0) std::cout<<"N "; else std::cout<<sum<<" "; sum=(clas[2]->size()); if(sum==0) std::cout<<"N "; else std::cout<<sum<<" "; sum=0; // iterbeg=((*clas[3]).begin()); iterend=((*clas[3]).end()); float aver=0.0; for(;iterbeg!=iterend;iterbeg++) { sum=sum+(*iterbeg); } aver=(float)sum/((*clas[3]).size()); if(sum==0) std::cout<<"N "; else printf("%0.1f ",aver); // iterbeg=((*clas[4]).begin()); iterend=((*clas[4]).end()); sum=*iterbeg; for(;iterbeg!=iterend;iterbeg++) if((*iterbeg)>sum) sum=*iterbeg; std::cout<<sum; return 0; }[/code][/code]