学习笔记
#include <time.h>
cout<<(double)clock()/CLOCKS_PER_SEC<<endl;
#include<iostream>
#define max(a,b) (((a) > (b)) ? (a) : (b))
using namespace std;
//十六进制输入输出cin>>hex>>n;cout<<hex<<n<<endl;
//十进制输入输出cout<<dec;
//__int64 a;
//__int64 值类型表示值介于 -9,223,372,036,854,775,808 到 +9,223,372,036,854,775,807 之间的整数。
printf("%I64d\n",x);
//long long a;
cout<<a<<endl;printf("%lld\n",a);
//填充函数:memset(string,a,sizeof(string));把string中填满a
/*将int类型的数转化为字符串类型:*itoa( value, string,10);
头文件:#include<stdlib.h>*/
//快速排序:#include <algorithm>
void qsort ( * base, num, sizeof(int), cmp )
base是要sort的数组的起始位置
num是要sort的个数
size是要sort的元素的大小
cm是个函数,用来比较两个元素的大小
int cmp (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}//从小到大
struct In{
int data;
bool flg;
}x[100];
int cmp( const void *a ,const void *B)
{
return (*(struct In *)a).data > (*(struct In *)B).data ? 1 : -1;
}
qsort(x,4,sizeof(x[0]),cmp);
多级排序
struct node
{
int n,c,k;
}len[1004];
int cmp( const void *a , const void *b )
{
struct node *c = (node *)a;
struct node *d = (node *)b;
if(c->n != d->n) return c->n - d->n;
else if(c->c!=d->c) return c->c - d->c;
else return c->k-d->k;
}
qsort(len,m,sizeof(node),cmp);
//#include <algorithm>
排序sort(a,a+n);
bool cmp(string a,string b)
{
if(a.compare(b)>=0)
return 0;
else
return 1;
}
sort(a,a+n,cmp);//升序排序
/*main()
{
int a=0x65,n,b;
cout <<a<<endl;
cin>>hex>>n;
cin>>dec>>b;
cout<<n<<endl;
cout<<hex<<n<<endl;
cout <<dec<<a<<endl;
cout <<dec<<b<<endl;
return 0;
}*/
//将int类型的数转化为字符串类型:*itoa( value, string,10);
/*#include<stdlib.h>
#include<string>
main()
{
int value=17,b;
cout<<hex<<value<<endl;
char string[15];
//memset(string,'\0',15);
cout<<sizeof(string)<<' ';
b=*itoa( value, string,16);
cout<<strlen(string)<<' '<<endl;
for(int i=0;i<strlen(string);i++)
cout<<string[i]<<' ';
cout<<endl;
cout<<b<<endl;
return 0;
}*/
/*指定小数点长度 #include<iomanip>
cout<< setw(21)<< fixed << setprecision(2) << a << endl;*/
文件输入输出:
#include<fstream>
ofstream fout("fout.txt");
ifstream fin("fin.txt");
随机数的生成:
#include <algorithm>
#include <cmath>
srand((unsigned)time(NULL));
for(i=0;i<10;i++)
cout<<rand()%n<<' ';
cout<<long((double)rand()/RAND_MAX * MAX_RAND)<<' ';