字符串tip

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;
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值