Simulation small note

[P1098] launched a string

[P1042] Table Tennis

Lz do simulated crashes growing;

Please put an "I want to climb step by step."

[P1098] launched a string

ac this problem experience: 50-60-70-80-100;

Middle is also mixed several times forgot to turn off freopen 0;

Analog is the devil!

Mo is thought to have nothing to talk about, is to pay attention to the following points:

1. consecutive '-' direct output

2 .'- 'appears at the beginning or end of the direct output

3. When the '-' character ends respectively while the numbers and letters, is output.

Then no:

#include<bits/stdc++.h>

using namespace std;

inline int read() {
    int ans=0;
    char last=' ',ch=getchar();
    while(ch>'9'||ch<'0') last=ch,ch=getchar();
    while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
    if(last=='-') ans=-ans;
    return ans;
}

int p1,p2,p3;
char a[200];

int main() {
    p1=read();
    p2=read();
    p3=read();
    p3--;
    scanf("%s",a);
    int len=strlen(a);
    for(int i=0; i<len; i++) {
        if(a[i]=='-') {
            if(i==0||i==len-1){
                printf("-");
                continue;
            }
            if(a[i+1]=='-'||a[i-1]=='-'){
                printf("-");
                continue;
            }
            char before=a[i-1],after=a[i+1];
            if(before>=after) {
                printf("%c",a[i]);
                continue;
            }
            if(before+1==after)    continue;
            if((before>='0'&&before<='9'&&(after>'9'||after=='-'))||(after>='0'&&after<='9'&&(before>'9'||before=='-'))) {

                printf("%c",a[i]);
                continue;
            }
            if(before>='0'&&before<='9'&&after>='0'&&after<='9') {
    
                if(p1==3) {
                    int x=after-before;
                    x--;
                    x*=p2;
                    for(int i=1; i<=x; i++)
                        printf("*");
                } else {
                    if(p3) {
                        int y=after-before;
                        y--;
                        char z=after-1;
                        int cnt=0;
                        for(int i=1; i<=y*p2; i++) {
                            if(cnt==p2) {
                                cnt=0;
                                z-=1;
                            }
                            printf("%c",z);
                            cnt++;
                        }
                    } else {
                        int y=after-before;
                        y--;
                        char z=before+1;
                        int cnt=0;
                        for(int i=1; i<=y*p2; i++) {
                            if(cnt==p2) {
                                cnt=0;
                                z+=1;
                            }
                            printf("%c",z);
                            cnt++;
                        }
                    }
                }
            }
            if(before>='a'&&before<='z'&&after>-'a'&&after<='z') {
                if(p1==3) {
                    int x=after-before;
                    x--;
                    x*=p2;
                    for(int i=1; i<=x; i++)
                        printf("*");
                } 
                if(p1==1) {
                    if(p3) {
                        int y=after-before;
                        y--;
                        char z=after-1;
                        int cnt=0;
                        for(int i=1; i<=y*p2; i++) {
                            if(cnt==p2) {
                                cnt=0;z-=1;
                            }
                            printf("%c",z);cnt++;
                        }
                    } else {
                        int y=after-before;
                        y--;
                        char z=before+1;
                        int cnt=0;
                        for(int i=1; i<=y*p2; i++) {
                            if(cnt==p2) {
                                cnt=0;z+=1;
                            }
                            printf("%c",z);cnt++;
                        }
                    }
                }
                if(p1==2){
                    if(p3) {
                        int y=after-before;y--;
                        char z=after-33;
                        int cnt=0;
                        for(int i=1; i<=y*p2; i++) {
                            if(cnt==p2) {
                                cnt=0;z-=1;
                            }
                            printf("%c",z);cnt++;
                        }
                    } else {
                        int y=after-before;    y--;
                           char z=before-31;
                        int cnt=0;
                        for(int i=1; i<=y*p2; i++) {
                            if(cnt==p2) {
                                cnt=0;z+=1;
                            }
                            printf("%c",z);cnt++;
                        }
                    }
                }
            }
        } else printf("%c",a[i]);
    }
    return 0;
}

 [P1042] Table Tennis

Congratulations lz hi mentioned difference tennis 11 minutes and 21 minutes braking system;

Anyway, this problem is not speaking very clearly;

11-point scale:

When a score of 11 points one and two points difference> = 2, it is determined that one of the 11 points to win, it is possible to output a score. When the score of 11 points, but either both points difference <2, the game continues, until the difference between the two sub> = 2;

21-point and 11-point rule is substantially the same, only the 11 minutes to 21 minutes;

Then special attention to the beginning of the sentence in the case of E appears: EWWW ......, direct output 0: 0 \ n \ n0: 0;

I then a single character read by a bool array a recorded is W (1 Chihuahua win) or L (0 competitor win), and then used to scan, when a [i] = 1, hh ++; otherwise ds ++;

Conditions are then output: Hua Hua and one opponent score> = 11 and the absolute value of their difference score> = 2, so that you can not and will in all cases be upstairs score system appears to have covered;

#include<bits/stdc++.h>

using namespace std;

bool a[62511];
int hh,ds;

int main() {
    int cnt=0;
    char ch;
    while(ch!='E') {
        ch=getchar();
        if(ch=='W') a[++cnt]=1;
        if(ch=='L') a[++cnt]=0;
    }
    if(cnt==0) printf("0:0\n\n0:0");
    for(int i=1; i<=cnt; i++) {
        if(a[i]) hh++;
        else ds++;
        if((hh>=11||ds>=11)&&abs(hh-ds)>=2) {
            printf("%d:%d\n",hh,ds);
            hh=ds=0;
        }
        if(i==cnt) printf("%d:%d\n",hh,ds);
    }
    printf("\n");
    hh=ds=0;
    for(int i=1; i<=cnt; i++) {
        if(a[i]) hh++;
        else ds++;
        if((hh>=21||ds>=21)&&abs(hh-ds)>=2) {
            printf("%d:%d\n",hh,ds);
            hh=ds=0;
        }

        if(i==cnt&&i%21!=0) printf("%d:%d",hh,ds);
    }
    return 0;
}

end-

Guess you like

Origin www.cnblogs.com/zhuier-xquan/p/11121722.html