insert函数
// inserting into a string
#include <iostream>
#include <string>
int main ()
{
std::string str="to be question";
std::string str2="the ";
std::string str3="or not to be";
std::string::iterator it;
/// used in the same order as described above:
str.insert(6,str2);
/// to be (the )question
str.insert(6,str3,3,4);
/// to be (not )the question
str.insert(10,"that is cool",8);
/// to be not (that is )the question
str.insert(10,"to be ");
/// to be not (to be )that is the question
str.insert(15,1,':');
/// to be not to be(:) that is the question
it = str.insert(str.begin()+5,',');
/// to be(,) not to be: that is
the question
str.insert (str.end(),3,'.'); // to be, not to be: that is the question(...)
str.insert (it+2,str3.begin(),str3.begin()+3);
/// (or )
std::cout << str << '\n';
return 0;
}
输入里有汉字:
要用unsigned char c;
一个汉字会被分成2个char存储。
2 n 2^n 2n:
#include<cmath>
#include<algorithm>
pow(2,n);
- 大整数乘法
struct BIGINT {
int cnt;
int v[1001];
};
void MUL(BIGINT* p, int a)
{
int carry = 0;
for (int i = 0; i < p->cnt; i++)
{
int t = p->v[i] * a + carry;
p->v[i] = t % 10;
carry = t / 10;
}
while (carry > 0)
{
p->v[p->cnt++] = carry % 10;
carry /= 10;
}
/*cout <<"IN"<<endl;
for(int i=p->cnt-1;i>=0;i--)
cout << p->v[i];
cout <<endl;*/
}
并查集
int find(int x)
{
if (f[x] == x)return x;
return f[x] = find(f[x]);
}
void set(int x, int y)
{
x = find(x);
y = find(y);
if(x!=y){
f[y]=x;
}
}