正文

10312006-06-08 17:20:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bakers/15594.html

分享到:

删除重复元素 Time Limit:1000MS  Memory Limit:65536KTotal Submit:18 Accepted:11 Description 对于一个已排序的数组,用一个算法来删除里面重复的元素。 Input 一个已排序的数组。最多不超过10000个元素。 Output 将数组删除重复元素后得到的数组 Sample Input 1 1 2 2 3 4 5 5 6 6 6 7 8 8 8 9 9 9 10 Sample Output 1 2 3 4 5 6 7 8 9 10  Source #include"iostream" #include"vector" using namespace std; vector<long>order; int main() { long i,j; while(cin>>i) order.push_back(i); for(j=0;j<order.size()-1;) if(order[j]==order[j+1]) { order.erase(order.begin()+j); } else j++; for(j=0;j<order.size();j++) cout<<order[j]<<" "; return 1; }

阅读(6241) | 评论(43)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册