字符串展开

题目大意:

一串缩写的字符串,将它缩写前的输出来(详情见原题)

原题

【模拟】字符串展开

解题思路:

直接模拟每一个字符即可

代码:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
int p1,p2,p3,l;
string str;
int main()
{
	scanf("%d %d %d",&p1,&p2,&p3);
	cin>>str;
	l=str.size();
	str=' '+str;
	for (int i=1;i<=l;++i)
	  {
	  	if (str[i]=='-')//判断是否为神略部分
	  	  {
	  	  	if (str[i-1]>='0'&&str[i-1]<='9'&&str[i+1]>str[i-1]&&str[i+1]<='9')//数字
	  	  	  {
	  	  	  	if (p3==1)//无需倒叙
	  	  	  	for (int j=str[i-1]+1;j<str[i+1];++j)//所有省略的字符
	  	  	  	  for (int k=1;k<=p2;++k)//输出的个数
	  	  	  	    if (p1==3) putchar('*');//判断是否要改为“*”
	  	  	  	    else putchar(j);
	  	  	  	else//要倒序
	  	  	  	for (int j=str[i+1]-1;j>str[i-1];--j)//反过来
	  	  	  	  for (int k=1;k<=p2;++k)//同上
	  	  	  	    if (p1==3) putchar('*');
	  	  	  	    else putchar(j);
	  	  	  	continue;
	  	  	  }
	  	  	if (str[i-1]>='a'&&str[i-1]<='z'&&str[i+1]>str[i-1]&&str[i+1]<='z')
	  	  	  {
	  	  	  	if (p3==1)
	  	  	  	for (int j=str[i-1]+1;j<str[i+1];++j)
	  	  	  	  for (int k=1;k<=p2;++k)
	  	  	  	    if (p1==3) putchar('*');
	  	  	  	    else if (p1==2) putchar(j-32);
	  	  	  	    else putchar(j);
	  	  	  	else
	  	  	  	for (int j=str[i+1]-1;j>str[i-1];--j)
	  	  	  	  for (int k=1;k<=p2;++k)
	  	  	  	    if (p1==3) putchar('*');
	  	  	  	    else if (p1==2) putchar(j-32);//大写
	  	  	  	    else putchar(j);
	  	  	  	continue;
	  	  	  }
	  	  }
	  	putchar(str[i]);//不是省略的就直接输出
	  }
}

相关文章:

  • 2021-05-21
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2021-05-24
  • 2021-06-03
  • 2021-12-30
  • 2022-12-23
相关资源
相似解决方案