【NOIP2007】【Luogu1098】字符串的展开
原创
©著作权归作者所有:来自51CTO博客作者小哈里1139的原创作品,请联系作者获取转载授权,否则将追究法律责任
problem
solution
codes
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
void print(char a, int b){ for(int i = 0; i < b; i++)cout<<a; }
int main(){
int n, m, k;
cin>>n>>m>>k;
string s; cin>>s;
//cout<<s[0];
for(int i = 0; i < s.size(); i++){
if(s[i]!='-'||s[i-1]>=s[i+1]){cout<<s[i]; continue;}
if(!(((s[i-1]>='a'&&s[i-1]<='z')&&(s[i+1]>='a'&&s[i+1]<='z'))||((s[i-1]>='0'&&s[i-1]<='9')&&(s[i+1]>='0'&&s[i+1]<='9')))){cout<<s[i]; continue;}
if(s[i-1]+1==s[i+1])continue;
if(n==1){
if(k==1)
for(int j = s[i-1]+1; j < s[i+1]; j++)
print(j,m);
else
for(int j = s[i+1]-1; j > s[i-1]; j--)
print(j,m);
}else if(n==2){
if(k==1)
for(int j = s[i-1]+1; j < s[i+1]; j++)
if(j>='a'&&j<='z')print(j-'a'+'A',m);
else print(j,m);
else
for(int j = s[i+1]-1; j > s[i-1]; j--)
if(j>='a'&&j<='z')print(j-'a'+'A',m);
else print(j,m);
}else
print('*', m*(s[i+1]-s[i-1]-1));
}
return 0;
}