c++ 点滴
Cassie曹
这个作者很懒,什么都没留下…
展开
-
函数模板 类模板
函数模板对于功能相同而只是数据类型不用的函数,不必定义各个函数,可采用对任何类型变量进行操作的函数模板。#include#include#include#includeusing namespace std;templateT fun(T a,T b){ return (a>=b)?a:b;}int main(){ int a=1,b=2; int tmp=fun原创 2016-05-15 11:47:54 · 264 阅读 · 0 评论 -
map的erase函数用法与注意
map record; map::iterator it; it=record.begin(); while(it!=record.end()){ int flag=-1; for(int i=0;i<k;i++){ flag=0; } if(flag){ record.erase(it++); }else{ it++; }原创 2016-06-19 09:36:15 · 3877 阅读 · 0 评论 -
map排序方法
map的进行排序:1.key排序是默认的,从小到大默认排序2.value需要借助vector进行排序,首先把map中数据放到vector中,然后利用sort对vector排序struct User{ int score[MaxK]; int sum; int full_cnt; int rank;};map record;vectorpair > result;原创 2016-06-19 09:46:45 · 2332 阅读 · 0 评论 -
跳台阶
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。IDEAn=1时,只有一种跳法,f(1)=1;n=2时,有两种跳法,f(2)=2;青蛙每次可跳1级或2级,若在有n级台阶时,它第一次跳了1级,剩下n-1级,有f(n-1)中跳法;如果它第一次跳了2级,则剩下n-2级,有f(n-2)种跳法;所以共有f(n-1)+f(n-2)种跳法。推出原创 2016-12-06 10:57:22 · 206 阅读 · 0 评论