Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
72926 冯诚阳 字符串展开 C++ Accepted 0 MS 272 KB 943 2024-05-14 17:20:19

Tests(6/6):


Code:

# include<iostream> # include<cstring> # include<cmath> using namespace std; char s[110]; int p1,p2,p3; void print(char a,char b){ bool x; //检查能不能展开,顺便标记是数字or字母 if(a>='0'&&a<='9'&&b>='0'&&b<='9'&&a<b)x=0; else if(a>='a'&&a<='z'&&b>='a'&&b<='z'&&a<b)x=1; else{//不能展开 cout<<"-"; return; } if(p3==1){//正序 for(char i=a+1;i<b;i++) for(int j=1;j<=p2;j++){ if(p1==3)cout<<"*";//输出“*” else if(p1==2&&x==1)cout<<char(i-32);//大写 else cout<<i; } } else{//倒序 for(char i=b-1;i>a;i--) for(int j=1;j<=p2;j++){//同上 if(p1==3)cout<<"*"; else if(p1==2&&x==1)cout<<char(i-32); else cout<<i; } } } int main() { while(cin>>p1>>p2>>p3){//多组数据 cin>>s; for(int i=0;i<strlen(s);i++){ if(s[i]!='-')cout<<s[i]; else print(s[i-1],s[i+1]); } cout<<endl<<endl; } return 0; }