STL
来源:互联网 发布:水果老虎机算法 编辑:程序博客网 时间:2024/06/01 14:32
第一次调用sort函数成功
参考调用sort函数简单的c++程序(目前还不会C++):
#include <stdio.h>#include <algorithm>using namespace std;int a[] = {12,3,35,8,-19,1999,100,9,0,23};struct Data{int data;int num;}data[10];//打印数组void print1(){for(int i = 0; i < 10; i++){printf("%d ",a[i]);}printf("\n");}//数组排序void sort1(){sort(a,a+10);}//结构体数组赋值void insert(){for(int i = 0; i < 10; i++){data[i].data = a[i];}}//打印结构体数组void print2(){for(int i = 0; i < 10; i++){printf("%d ",data[i].data);}printf("\n");}//结构体数组排序函数int cmp(const Data &a,const Data &b){if(a.data > b.data)//降序排列return 1;else return 0;}//结构体数组排序void sort2(){sort(data,data+10,cmp);//sort(data,data+10);}int main(){//结构体数组赋值insert();//数组排序printf("数组排序前:\n");print1();sort1();printf("数组排序后:\n");print1();//结构体数组排序printf("结构体数组排序前:\n");print2();sort2();printf("结构体数组排序后:\n");print2();}还有博文:http://blog.csdn.net/zzzmmmkkk/article/details/4266888/
讲述了C++ 排序函数 sort(),qsort()的用法
我便写出的程序HDU水题1678:
#include <stdio.h>#include<string.h>#include <algorithm>using namespace std;void sort1(int p[],int n){sort(p,p+n);}int main(){ void sort(int s[],int n); int t,i,p[20001],n; long long ans; scanf("%d",&t); while(t--){ scanf("%d",&n); memset(p,0,sizeof(p)); for(i=0;i<n;i++){ scanf("%d",&p[i]); } sort1(p,n); for(i=3,ans=0;i<=n;i+=3){ ans+=p[n-i]; } printf("%lld\n",ans); } return 0;}
使用冒泡排序会超时,SO要使用sort函数。
然后成功AC。
^_^ <_> 还有打字速度在逐渐提升呦!
继续坚持,另外注意身体健康。
0 0
- stl
- stl
- STL
- STL
- STL
- STL
- STL
- STL
- STL
- stl
- STL
- STL
- STL
- STL
- STL
- STL
- STL
- STL
- ES6新特性概览
- OpenGL 着色器语言
- 创建自己的“JavaScript库”
- jq-基本知识
- -Dmaven.multiModuleProjectDirectory system propery is not set.
- STL
- Setting Up Continuous Integration & Continuous Deployment With Jenkins
- 欢迎使用CSDN-markdown编辑器
- codeforces 277E - Binary Tree on Plane (MinCostMaxFlow, 简单)
- Checking for Undefined, Null, and Empty Variables in JavaScript
- jq-跨域请求
- 我真的不懂微信营销(一)
- failed to sync branch You might need to open a shell and debug the state of this repo.
- 单链表实现插入排序