【replace的用法】第三届ACM/ICPC程序设计知识竞赛网络赛—— 字符串扩展
2013-05-26 22:42
337 查看
来源:点击打开链接
可以用replace来替换。。replace的用法中很有用的两个:
1、用string 中从 _Pos2 开始的 _Num2 个字符,代替操作string 中从 _Pos1 开始的 _Num1 个字符
用C-string 中的 _Num2 个字符,代替操作string 中从 _Pos1 开始的 _Num1 个字符
basic _ string& replace( size _ type _Pos1 , size _ type _Num1 , const basic _ string& _Str , size _ type _Pos2 , size _ type );
basic _ string& replace( size _ type _Pos1 , size _ type _Num1 , const value _ type* _Ptr , size _ type _Num2 );
2、用 _Count 个character _Ch , 代替操作string 中从 _Pos1 开始的 _Num1 个字符
basic _ string& replace( size _ type _Pos1 , size _ type _Num1 , size _ type _Count , value _ type _Ch );
可以用replace来替换。。replace的用法中很有用的两个:
1、用string 中从 _Pos2 开始的 _Num2 个字符,代替操作string 中从 _Pos1 开始的 _Num1 个字符
用C-string 中的 _Num2 个字符,代替操作string 中从 _Pos1 开始的 _Num1 个字符
basic _ string& replace( size _ type _Pos1 , size _ type _Num1 , const basic _ string& _Str , size _ type _Pos2 , size _ type );
basic _ string& replace( size _ type _Pos1 , size _ type _Num1 , const value _ type* _Ptr , size _ type _Num2 );
2、用 _Count 个character _Ch , 代替操作string 中从 _Pos1 开始的 _Num1 个字符
basic _ string& replace( size _ type _Pos1 , size _ type _Num1 , size _ type _Count , value _ type _Ch );
#include <iostream> #include <string> #include <ctype.h> using namespace std; string lowalp="abcdefghijklmnopqrstuvwxyz"; string uppalp="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string numalp="0123456789"; int main() { int testcase; string tar,res; cin>>testcase; while(testcase--) { cin>>tar; int chanpos; int startrep=0,enrep=0; char st,ed; for(int i=1;i<tar.length();i++) { if(tar[i]=='-') { chanpos=i; st=tar[i-1]; ed=tar[i+1]; if(islower(st) && islower(ed) && st<ed) { startrep=lowalp.find(st,0); enrep=lowalp.find(ed,0); tar.replace(i,1,lowalp,startrep+1,enrep-startrep-1); //cout<<tar<<endl; } else if(isupper(st) && isupper(ed) && st<ed) { startrep=uppalp.find(st,0); enrep=uppalp.find(ed,0); tar.replace(i,1,uppalp,startrep+1,enrep-startrep-1); //cout<<tar<<endl; } else if(isdigit(st) && isdigit(ed) && st<ed) { startrep=numalp.find(st,0); enrep=numalp.find(ed,0); tar.replace(i,1,numalp,startrep+1,enrep-startrep-1); } else if(st==ed &&((isupper(st)&&isupper(ed))||(islower(st)&&islower(ed))||(isdigit(st)&&isdigit(ed)))) { tar.erase(chanpos,1); //trick } } } cout<<tar<<endl; } }
相关文章推荐
- 【replace的用法】第三届ACM/ICPC程序设计知识竞赛网络赛—— 字符串扩展
- sdut 第三届ACM/ICPC程序设计知识竞赛网络赛 字符串拓展
- ACM/ICPC黑龙江省第四届大学生程序设计竞赛网络预选赛有感
- 安徽大学第三届ACM/ICPC 程序设计竞赛现场赛-取数字问题
- ACM学习历程—NPU 2015年陕西省程序设计竞赛网络预赛(正式赛)F题 和谐的比赛(递推)
- ACM学习历程—SNNUOJ 1110 传输网络((并查集 && 离线) || (线段树 && 时间戳))(2015陕西省大学生程序设计竞赛D题)
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛(热身赛)
- 2013“嘉杰信息”杯ACM/ICPC湘潭多省程序设计竞赛暨湘潭市第五届大学生程序设计竞赛
- XTU OJ 1209 Alice and Bob 2014(嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛)
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛 解题报告
- Mine Number(2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛)
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛——Fruit Ninja II
- 山东省第三届ACM大学生程序设计竞赛(待添加)
- SDUT 2408 Pick apples(完全背包+贪心)2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛
- 山东省第三届ACM大学生程序设计竞赛-Pixel density(模拟)
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛 -Happy Number
- 山东省第三届ACM大学生程序设计竞赛 n a^o7 !
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛 The Best Seat in ACM Contest 看清题目后,我是真哭了。。。。。
- ACM/ICPC中国•辽宁省第二届大学生程序设计竞赛通知