部分内容来自网上~
输入输出:
printf输出float和double都可以用%f,double还可以用%lf。
scanf输入float用%lf,double输入用%lf,不能混用。
long long 用%lld。
printf("%d\n",i>>1 );
printf("%10.2f\n",d );//右对齐,占10位字符,保留2位小数。
printf("%-10.2f\n",d );//左对齐,占10位字符,保留2位小数。
printf("%s\n",s );//输出字符串
fprintf(stderr, "%s\n", );//输出到文件
sprintf(s,"%d%d",a,b);//输出到字符串s中
sscanf(s,"%d:%d:%d",&h,&m,&s)//从s(例如s=“12:59:59”)中读取h,m,s。
读取一行(包括空格)(注意使用前别忘了用getchar()吸收回车符):
fgets(s,sizeof s,stdin);
gets(s);//有缓冲区溢出危险
自定义STL优先队列的优先级:
//定义结构,使用运算符重载,自定义优先级1
struct cmp1{
bool operator ()(int &a,int &b){
return a>b;//最小值优先
}
};
struct cmp2{
bool operator ()(int &a,int &b){
return a<b;//最大值优先
}
};
//定义结构,使用运算符重载,自定义优先级2
struct number1{
int x;
bool operator < (const number1 &a) const {
return x>a.x;//最小值优先
}
};
struct number2{
int x;
bool operator < (const number2 &a) const {
return x<a.x;//最大值优先
}
};
priority_queue<int>que;//采用默认优先级构造队列
priority_queue<int,vector<int>,cmp1>que1;//最小值优先
priority_queue<int,vector<int>,cmp2>que2;//最大值优先
priority_queue<int,vector<int>,greater<int> >que3;//最小值优先。注意“> >”的空格。
priority_queue<int,vector<int>,less<int> >que4;//最大值优先
priority_queue<number1>que5;
priority_queue<number2>que6;
string流的用法(以Hdu 2072为例):
//题目大意:输入一行英文句子,输出共有多少不同的单词。
#include <sstream>
set<string>s;
string row,word;
while(getline(cin,row) && row!="#" ){
s.clear();
stringstream str_cin(row);
while(str_cin>>word){
s.insert(word);
}
cout<<s.size()<<endl;
}
原文:http://www.cnblogs.com/bruce27/p/4557721.html