OJ中的奇技淫巧
使用异或进行swap
1
2
3
4
5void swap(int& a,int& b){
a=a^b;
b=a^b;
a=a^b;
}
单行多字符串处理
1
2
3
4
5
6
7
8
9
10
11
12
using namespace std;
int main(){
string s;
getline(cin,s);
stringstream ss;
ss<<s;
while(ss>>s){
cout<<s<<endl;
}
return 0;
}
加快cin速度
1
std::ios::sync_with_stdio(false);
while和scanf
1
2
3
4
5
6
7
8
9
10//读到文件的结尾,程序自动结束
while( ( scanf( " %d " ,&a) ) != -1 )
while( ( scanf( " %d " ,&a) ) != EOF)
while( ( scanf( " %d " ,&a) ) == 1 )
while( ~( scanf( " %d " ,&a) ) )
//读到一个 0 时,程序结束
while( scanf( " %d " ,&a) ,a)
//读到多个0时,程序结束
while( scanf( " %d%d%d " ,&a,&b,&c),a+b+c ) //a,b,c非负
while( scanf( " %d%d%d " ,&a,&b,&c),a|b|c )
vector定义二维数组
1
2int len=100;
vector<vector<int> > dp(len,vector<int>(len,0));