C++入门程序作业1
将一个int A[]={ , , ,}定义的可能重复的数字去掉重复的元素。
了解向量,容器如何使用,size,地址的关系,理解unique erase函数的返回值是什么参数
结果:将1,1,1,2,2,2,3,3,3,4,4,4,5,5,5消去变成1,2,3,4,5
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
#include <iterator>
using namespace std;
int main()
{
//cout<<"Illustrating the generic unique algorithm."<<endl;
const int N=15;
int array1[N]={1,1,1,2,2,2,3,3,3,4,4,4,5,5,5};
vector<int> vector1;
for (int i=0;i<N;++i)
vector1.push_back(array1[i]);
// cout<<array1<<endl;
vector<int>::iterator new_end;
new_end=unique(vector1.begin(),vector1.end()); //"删除"相邻的重复元素
cout<<*new_end<<endl;
for (int i=0;i<vector1.size();i++)
cout << vector1[i] << " "; //
cout << endl;
return 0;
}
-------------------------------------------------------------------- --------------------------------------------------------------------
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
void main()
{
int A[12] = {1,1,1,2,2,2,3,3,3,4,4,4};
vector<int> a;
for (int i=0;i<12;i++)
a.push_back(A[i]);
for (int i=0;i<a.size();i++)
cout << a[i] << " "; //
cout << endl;
a.erase(unique(a.begin(),a.end()),a.end());
for (int i=0;i<a.size();i++)
cout << a[i] << " "; //
cout << endl;
//
}
C++入门程序作业1的更多相关文章
- C++入门程序作业2
程序在Dev-C++5.5.3版本运行 结构体的使用 给结构体赋值,打印出结构体中学生姓名,分数,平均分 #include <iostream>#include <cassert&g ...
- C++入门程序作业3
/* 输出n位数据的格雷码 The gray code is a binary numeral system where two successive values differ in only on ...
- mybatis入门_mybatis基本原理以及入门程序
一.传统jdbc存在的问题 1.创建数据库的连接存在大量的硬编码, 2.执行statement时存在硬编码. 3.频繁的开启和关闭数据库连接,会严重影响数据库的性能,浪费数据库的资源. 4.存在大量的 ...
- 1.struts2原理和入门程序
Struts2是一个MVC的Web应用框架,是在Struts1和WebWork发展起来的,以WebWork为核心,采取拦截器机制来处理用户请求. 原理图: 分析步骤: 1.用户发送一个请求 2.请求的 ...
- springMVC2 1入门程序
1入门程序 .1需求 实现商品列表查询 .2需要的jar包 使用spring3.2.0(带springwebmvc模块) .1前端控制器 在web.xml中配置: <?xml version=& ...
- struts2入门程序
struts2入门程序 1.示例 搭建编程环境就先不说了,这里假设已经搭建好了编程环境,并且下好了strut2的jar包,接下来程序. 1.1 新建web项目 点击File->New->D ...
- Spring+SpringMVC+MyBatis深入学习及搭建(十二)——SpringMVC入门程序(一)
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6999743.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十一)——S ...
- springmvc(一) springmvc框架原理分析和简单入门程序
springmvc这个框架真的非常简单,感觉比struts2还更简单,好好沉淀下来学习~ --WH 一.什么是springmvc? 我们知道三层架构的思想,并且如果你知道ssh的话,就会更加透彻的理解 ...
- python web入门程序
python2.x web入门程序 #!/usr/bin/python # -*- coding: UTF-8 -*- # 只在python2.x 有效 import os #Python的标准库中的 ...
随机推荐
- sql字符串根据日期产生日期+自增长标志
select Convert(varchar(6), '20180614 20:19:04', 12) + SubString('0000' + Convert(varchar(6), 1 + 1), ...
- Django web框架-----Django templates模板
说明:mytestsite是django框架下的项目,quicktool是mytestsite项目中的应用 一般的变量之类的用 {{ }}(变量),功能类的比如循环.条件判断是用 {% %}(标签) ...
- 使用 HttpClient 进行文件上传
1.使用 AddPart 方法 public static void upload(String authorization,String baseUrl,String filePath,String ...
- .net core 获取本地ip及request请求端口
1.获取ip和端口 string str = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + " ...
- eslint常用关闭校验语句
1. 关闭段落校验 /* eslint-disable */some code some code /* eslint-enable */ 2. 关闭当前行校验 some code // eslint ...
- 使用Notepad++编译运行C/C++/Python程序
对我来说,比较常用的是C/C++/Python. 使用Notepad++编译运行单个源文件的C/C++/Python,比使用复杂的IDE更加快捷. 想要让Notepad++能够做到编译运行C/C++/ ...
- css选择器权重问题
important infinity 行间样式 1000(256进制) id 100 class/属性/伪类 10 标签/伪元素 1 通配符 0
- centes7安装wdcp
CentOS7安装WDCP3 CentOS7安装WDCP3.2面板教程 到此WDCP安装完毕
- work2:贪吃蛇
学号:2017*****7219 姓名:邰嘉琛我的码云贪吃蛇项目仓库:https://gitee.com/tjc666/sesnake/tree/master2) 给出你的各项任务完成时间估算与实际消 ...
- SSM中的Mybatis的操作
一:整合日志含有log4j和logback logback是log4j的升级版他性能提升较大,有些甚至达到10倍以上,占的内存更小,slf4j能很好的整合它,还有很多数不胜数的优势 1.下载jar包, ...