Luo Gu [explanations] P1098 string expansion

A flood problem. . . Yellow pure analog to now also saw a
first portal put it

Original title Portal

First, before writing this question, the first universal ASCII code. . . (This is what Intuit simple)
each have their own character ASCII value, such as the ASCII value of 65 A is
calculated ASCII value method

	char a;            //要计算ASCII码值的字符
	int b;               //存放ASCII码值
	cin>>a;
	b=int(a);        //强制转换,就能达到求ASCII码值的目的
	cout<<b;

Converting numbers to a character is also very simple, simply pour a fall program

	int a;                  //要求这个字符的ASCII码值
	char b;              //存放字符
	cin>>a;
	b=char(a);       //强制转换
	cout<<b;

Well, get down to business:
the Road simulation questions I spent a week's time. . . Mainly cancer data points. Some data points did not mentioned in the title, so I wasted five opportunities to download test data. . .
Speaking about the meaning of the questions before it:
Input:
enter three parameters p1, p2, p3, enter a string of string.

Output (Output press 7 cases):
replaced into the following 7 kinds minus situation:

(1) Regarding the parameters p1 (after all the other examples of parameters with the parameter p1 = 1)
When p1 = 1, when a letter of the ASCII code is greater than the right minus left minus sign letters ASCII code, in accordance with the letters 26 order to replace the minus sign to the letters to the left of the right middle all lowercase letters
Example: ad output abcd
when p1 = 2, converting the alternative. 1 p1 = out lowercase to uppercase
Example: ad output aBCd
when p1 = 3, the conversion of an alternative. 1 p1 = lowercase letters asterisk
Example: ad output a ** d

(2) parameter regarding p2
parameter p2 simple, when k = p2, p1 all alternatives in the output character is repeated k times.
Example: ad p2 = 2 output abbccd

(3) with respect to the parameters p3
parameter p3 is also very simple.
When p3 =. 1, all the output does not change, i.e. completely without the tube
when p3 = 2, the output of all characters output flashback
Example: ad p2 = 1, p3 = 2 output acbd

(4) When a minus sign at the beginning of the string, no matter how many are re-minus outputs
(5) When both sides of minus two letters are the same, the output of the intermediate therebetween minus two letters
(6) when ASCII characters to the right of the left minus value +1 is exactly the ASCII character, two characters output
(7) when the character ASCII code minus the left to the right is greater than the ASCII characters, two characters output minus sandwiching
(8) If the left and right sides minus side is digital, while the letters, characters sandwiched between two output minus

With these good, we can write a great simulation ### ...

Following the first offer codes

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
char a[233];
int p1,p2,p3;
void turn(char b,char c)
{
	if((int(b))==(int(c)-1))
    {
        return;
    }
    if(int(c)<=int(b))
    {
        cout<<"-";
        return;
    }
    if((int(b)>=48)&&(int(b)<=57))
    {
        if(int(c)>=65)
        {
            cout<<"-";
            return;
        }
    }
    if((int(c)>=48)&&(int(c)<=57))
    {
        if(int(b)>=65)
        {
            cout<<"-";
            return;
        }
    }
    if(p1==3)
    {
        int k=int(c)-int(b)-1;
        for(int i=0;i<k;i++)
        {
            for(int j=0;j<p2;j++)
            {
                cout<<"*";
            }
        }
        return;
    }
    if((int(b)>=48)&&(int(b)<=57))
    {
        if((int(c)>=48)&&(int(c)<=57))
        {
            if(int(b)>=(int(c)))
            {
                cout<<"-";
                return;
            }
            else
            {
                for(int i=(int(b)+1);i<(int(c));i++)
                {
                    for(int j=0;j<p2;j++)
                    {
                        cout<<(i-'0');
                    }
                }
            }
        }
        return;
    }
    if((p1==1)&&(p3==1))
    {
        for(int i=(int(b)+1);i<(int(c));i++)
        {
            for(int j=0;j<p2;j++)
            {
                if(i<97)
                {
                    cout<<char(i+32);
                }
                else cout<<char(i);
            }
        }
    }
    if((p1==1)&&(p3==2))
    {
        for(int i=(int(c)-1);i>(int(b));i--)
        {
            for(int j=0;j<p2;j++)
            {
                if(i<97)
                {
                	cout<<char(i+32);
                }
                else cout<<char(i);
            }
        }
    }
    if((p1==2)&&(p3==1))
    {
        for(int i=(int(b)+1);i<(int(c));i++)
        {
            for(int j=0;j<p2;j++)
            {
            	if(i>97)
            	{
            		cout<<char(i-32);
                }
                else cout<<char(i);
            }
        }
    }
    if((p1==2)&&(p3==2))
    {
        for(int i=(int(c)-1);i>(int(b));i--)
        {
            for(int j=0;j<p2;j++)
            {
                if(i>97)
                {
                	cout<<char(i-32);
                }
                else cout<<char(i);
            }
        }
    }
}
int main()
{
    scanf("%d %d %d",&p1,&p2,&p3);
    scanf("%s",a);
    int len=strlen(a);
    for(int i=0;i<len;i++)
    {
    	if(((a[i]=='-')&&(i==0))||((a[i]=='-')&&((a[i-1]=='-')||(a[i+1]=='-'))))
    	{
    		cout<<"-";
    		continue;
        }
        if(a[i]!='-')
        {
            printf("%c",a[i]);
        }
        else turn(a[i-1],a[i+1]);
    }
    return 0;
}

The key point of this code is the function of the turn, contains more than seven kinds of situations, write me physically and mentally exhausted. . .
Now one by one to split it according to the situation

	if((int(b))==(int(c)-1))
    {
        return;
    }
    if(int(c)<=int(b))
    {
        cout<<"-";
        return;
    }
    if((int(b)>=48)&&(int(b)<=57))
    {
        if(int(c)>=65)
        {
            cout<<"-";
            return;
        }
    }
    if((int(c)>=48)&&(int(c)<=57))
    {
        if(int(b)>=65)
        {
            cout<<"-";
            return;
        }
    }

And if all of the following for the outermost layer, which will say alone

First if: 6 corresponds to the point, is left to the right ASCII ASCII + 1
second if: 5 and the corresponding points 7 points: the left is greater than or equal to
a third, four if: corresponding point (8), both sides are not the same

	if(p1==3)
    {
        int k=int(c)-int(b)-1;
        for(int i=0;i<k;i++)
        {
            for(int j=0;j<p2;j++)
            {
                cout<<"*";
            }
        }
        return;
    }
    //当p1=3时,就可以直接填充星号
    if((int(b)>=48)&&(int(b)<=57))
    {
        if((int(c)>=48)&&(int(c)<=57))
        {
            if(int(b)>=(int(c)))
            {
                cout<<"-";
                return;
            }
            else
            {
                for(int i=(int(b)+1);i<(int(c));i++)
                {
                    for(int j=0;j<p2;j++)
                    {
                        cout<<(i-'0');
                    }
                }
            }
        }
        return;
    }
    //当左右两边都是数字时,判断,如果右>左,直接输出,不然按要求输出
    if((p1==1)&&(p3==1))
    {
        for(int i=(int(b)+1);i<(int(c));i++)
        {
            for(int j=0;j<p2;j++)
            {
                if(i<97)
                {
                    cout<<char(i+32);
                }
                else cout<<char(i);
            }
        }
    }
    if((p1==1)&&(p3==2))
    {
        for(int i=(int(c)-1);i>(int(b));i--)
        {
            for(int j=0;j<p2;j++)
            {
                if(i<97)
                {
                	cout<<char(i+32);
                }
                else cout<<char(i);
            }
        }
    }
    if((p1==2)&&(p3==1))
    {
        for(int i=(int(b)+1);i<(int(c));i++)
        {
            for(int j=0;j<p2;j++)
            {
            	if(i>97)
            	{
            		cout<<char(i-32);
                }
                else cout<<char(i);
            }
        }
    }
    if((p1==2)&&(p3==2))
    {
        for(int i=(int(c)-1);i>(int(b));i--)
        {
            for(int j=0;j<p2;j++)
            {
                if(i>97)
                {
                	cout<<char(i-32);
                }
                else cout<<char(i);
            }
        }
    }
    //最后就是枚举每一种情况,然后按要求输出

This is the horror of the parameters p1. . .
Although the code is long, but can be AC ah

    for(int i=0;i<len;i++)
    {
    	if(((a[i]=='-')&&(i==0))||((a[i]=='-')&&((a[i-1]=='-')||(a[i+1]=='-'))))
    	{
    		cout<<"-";
    		continue;
        }
        if(a[i]!='-')
        {
            printf("%c",a[i]);
        }
        else turn(a[i-1],a[i+1]);
    }

Finally, the main function inside the first if statement must be the next, or to another of the WA. . .

thank you all!

Guess you like

Origin blog.csdn.net/tidongCrazy/article/details/92008512