Files
python/C++专题课程/NOIP算法总结/字符串处理/字符串的展开/P1098.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

24 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<bits/stdc++.h>
using namespace std;
int p1,p2,p3,i=0,k;
char ch[300],be,af,f,j,p;//p用于输出;
int main() {
scanf("%d%d%d%s",&p1,&p2,&p3,ch);//输入;
while(ch[i]){//当ch[i]有值时;
be=ch[i-1];af=ch[i+1];f=ch[i];//f存储ch[i],便于判断;
if(f=='-'&&af>be&&(be>='0'&&af<='9'||be>='a'&&af<='z')){//意思是ch[i]若为'-',就判断其前后是否满足条件,满足进入循环;
for(p3==1?j=be+1:j=af-1; p3==1?j<af:j>be; p3==1?j++:j--){
p=j;//j是整形变量,p是字符型变量,这样是将p赋值为ASCII码为j的字符;
if(p1==2)//是否大写;
p=(p>='a')?p-32:p;//如果是字母就转成大写
else if(p1==3) p='*';//是否输出'*'
for(k=0; k<p2; k++)//输出p2个
printf("%c",p);
}
}
else
printf("%c",f);//如果ch[i]是非'-'或者其前后不满足条件,就原样输出;
i++;//一定要放在后面,不然会出错QAQ;
}
return 0;
}