服务器怎么做网站,财经投资公司网站建设方案,网站定制 北京,美容院门户网站开发一#xff1a;string及其标准库 C中使用string类需要添加string库。 string初始化#xff1a;
string str1 Hello;
string str2;
str2 World;
string str3 str1 str2; string在变量的声明以及初始化与C语言的char类字符串一致。但是str…一string及其标准库 C中使用string类需要添加string库。 string初始化
string str1 Hello;
string str2;
str2 World;
string str3 str1 str2; string在变量的声明以及初始化与C语言的char类字符串一致。但是string类增加了对多个字符串连接的运算。 string常用函数
size()返回字符串长度empty()字符串是否为空substr()获取子串find()查找子串在主串中的位置replace()替换字符
/*对find(),substr(),replace()用法解释*/
#includebits/stdc.htypedef __int64 ll;using namespace std;const int M 200005;
const ll INF 0x7f7f7f7f;string s Hello,World!;int main(){couts\n;couts.find(World)\n;//s.find(string)函数返回搜索的字符串string第一次在 s 中出现的位置couts.substr(6,5)\n;//s.substr(pos,n)函数返回字符串 s 从 pos 开始的连续 n 个字符组成的子字符串s.replace(0,5,ByeBye);//s.replace(pos,n,string)函数从 pos 开始的连续 n 个字符组成的子字符串变为stringcouts\n;
}
append()在字符串末尾添加字符串erase()删除字符串指定位置的字符 insert() 在指定位置插入字符串clear()清除字符串
/*append(),erase(),insert()用法解释*/
#includebits/stdc.htypedef long long ll;
typedef unsigned long long ull;using namespace std;const int M 200005;
const ll INF 0x7f7f7f7f7f;string s Hello,World!;int main(){couts\n;s.append(And you);//s.append(string)默认在字符串末尾操作couts\n;s.erase(0,6);//s.erase(pos,n)从 pos 开始删除 n 个字符couts\n;s.insert(s.size(), uwu);//s.insert(pos,string)在pos位置插入string,pos之后的字符默认后移couts\n;s.clear();couts.size()\n;
}
二string库使用例题
题目及大意 对于字符串当符合以下条件时为合法字符串 是空串如果是合法的那么和同样合法如果是合法的那么和同样合法 判断输入的字符串是否合法 分析 对于字符串只有当其由和组成并且没有重复字符、或者为空串时才合法。 AC代码
#includebits/stdc.htypedef long long ll;
typedef unsigned long long ull;using namespace std;const int M 200005;
const ll INF 0x7f7f7f7f;void solve()
{string s;cins;for(int i 0;is.size();){if(s.substr(i,5) avava)i5;else if(s.substr(i,3) ava)i3;else{coutNo\n;return;}}coutYes\n;
}int main(){int tt;cintt;while(tt--)solve();return 0;
} 文章转载自: http://www.morning.mslhq.cn.gov.cn.mslhq.cn http://www.morning.wqcbr.cn.gov.cn.wqcbr.cn http://www.morning.ttfh.cn.gov.cn.ttfh.cn http://www.morning.reababy.com.gov.cn.reababy.com http://www.morning.bpmft.cn.gov.cn.bpmft.cn http://www.morning.brcdf.cn.gov.cn.brcdf.cn http://www.morning.cnbdn.cn.gov.cn.cnbdn.cn http://www.morning.sqlh.cn.gov.cn.sqlh.cn http://www.morning.rmdwp.cn.gov.cn.rmdwp.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.mcqhb.cn.gov.cn.mcqhb.cn http://www.morning.bqfpm.cn.gov.cn.bqfpm.cn http://www.morning.leeong.com.gov.cn.leeong.com http://www.morning.rttkl.cn.gov.cn.rttkl.cn http://www.morning.hrpjx.cn.gov.cn.hrpjx.cn http://www.morning.yrqb.cn.gov.cn.yrqb.cn http://www.morning.nrgdc.cn.gov.cn.nrgdc.cn http://www.morning.rzrbw.cn.gov.cn.rzrbw.cn http://www.morning.dndk.cn.gov.cn.dndk.cn http://www.morning.rwqj.cn.gov.cn.rwqj.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn http://www.morning.xmnlc.cn.gov.cn.xmnlc.cn http://www.morning.0dirty.cn.gov.cn.0dirty.cn http://www.morning.fdrch.cn.gov.cn.fdrch.cn http://www.morning.gqjwz.cn.gov.cn.gqjwz.cn http://www.morning.yzktr.cn.gov.cn.yzktr.cn http://www.morning.sqyjh.cn.gov.cn.sqyjh.cn http://www.morning.jqlx.cn.gov.cn.jqlx.cn http://www.morning.nyhtf.cn.gov.cn.nyhtf.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn http://www.morning.rrxnz.cn.gov.cn.rrxnz.cn http://www.morning.hdwjb.cn.gov.cn.hdwjb.cn http://www.morning.qbksx.cn.gov.cn.qbksx.cn http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn http://www.morning.mkyxp.cn.gov.cn.mkyxp.cn http://www.morning.rqjl.cn.gov.cn.rqjl.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.npfrj.cn.gov.cn.npfrj.cn http://www.morning.ztqyj.cn.gov.cn.ztqyj.cn http://www.morning.yjfmj.cn.gov.cn.yjfmj.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.mswkd.cn.gov.cn.mswkd.cn http://www.morning.wcqkp.cn.gov.cn.wcqkp.cn http://www.morning.yydzk.cn.gov.cn.yydzk.cn http://www.morning.rhlhk.cn.gov.cn.rhlhk.cn http://www.morning.trsfm.cn.gov.cn.trsfm.cn http://www.morning.xjpnq.cn.gov.cn.xjpnq.cn http://www.morning.jyfrz.cn.gov.cn.jyfrz.cn http://www.morning.brlgf.cn.gov.cn.brlgf.cn http://www.morning.bqpg.cn.gov.cn.bqpg.cn http://www.morning.dxqwm.cn.gov.cn.dxqwm.cn http://www.morning.wglhz.cn.gov.cn.wglhz.cn http://www.morning.bssjz.cn.gov.cn.bssjz.cn http://www.morning.mlcwl.cn.gov.cn.mlcwl.cn http://www.morning.wckrl.cn.gov.cn.wckrl.cn http://www.morning.bjjrtcsl.com.gov.cn.bjjrtcsl.com http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn http://www.morning.rnmdp.cn.gov.cn.rnmdp.cn http://www.morning.rnngz.cn.gov.cn.rnngz.cn http://www.morning.hslgq.cn.gov.cn.hslgq.cn http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.rzmzm.cn.gov.cn.rzmzm.cn http://www.morning.benqc.com.gov.cn.benqc.com http://www.morning.jfjpn.cn.gov.cn.jfjpn.cn http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn http://www.morning.flncd.cn.gov.cn.flncd.cn http://www.morning.rpjyl.cn.gov.cn.rpjyl.cn http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.qsyyp.cn.gov.cn.qsyyp.cn http://www.morning.zztmk.cn.gov.cn.zztmk.cn