Brush title recording PAT 2019/5 / 22--2019 / 5 / 23--19 / 525

B 1009 ironic

gets and scanf difference

scanf&gets&getchar

scanf ()% s ignores all the rows beginning with the spaces, and spaces, newline input string is automatically added at the back end of string character '\ 0', so remember to open a certain character array than the actual length of the array length of the string stored in at least one more; enter, space will remain in the input buffer can be used getchar () statement read scanf after execution, the transport buffer is left blank. scanf% c can read the space with newline

gets () to read any character string starting to ending newline, but then discards the buffer line breaks and to '\ 0' instead;

Note: the end of an int array does not need to add '\ 0', only the character array needed.

First: pay attention to whether to accept a different function spaces, whether to reject the last carriage of the problem!
When reading character:
scanf () to end the Space, Enter, Tab once entered, do not accept spaces, will not give up and finally a carriage (i.e. carriage remains in the buffer);
getchar () enter to end the input, receiving spaces, not discard the last carriage;
reading string:
Scanf () in space , enter, Tab once ended input, do not accept spaces, carriage returns remain in the buffer
gets () to enter the end of the input (spaces are not the end), to accept the space, will give up the last carriage returns!

Note: When using C ++ compiler, there will be error: 'gets' was not declared in this scope, the solution ; the C compiler can not go wrong.

* Character can be used as a two-dimensional array using an array of strings.

* Note that for each string manually added to the end terminator '\ 0'

B 1014 / A 1061 Holmes appointments

. . . . . Enough's enough, and I changed this question for two hours. . . . . . Topic expression is not clear

Holmes dating pit Detailed

Han did not want to say

B 1024 / A 1073 scientific notation

Not a problem, but is more complicated to analyze, to sort things out.

The zi

String into a symbol, a real number, E, exponent portion

1. Locate the position pos E;

2. string to an integer part of the index

3. The classification index of the positive and negative and the processing discussed 0

#include <cstdio>
#include <cstring>
//字符串分解,符号、实数、E、指数
int main(){
    char str[10010];
    scanf("%s",str);
    int len=strlen(str);
    if(str[0]=='-')
        printf("-");
//获得E位置
    int pos=0;
    while(str[pos]!='E'){
        pos++;
    }
//获得指数
    int exp=0;
    for(int k=pos+2;k<len;k++){
        exp=exp*10+(str[k]-'0');
    }
//分类讨论指数正负
//指数为零,输出实数部分
    if(exp==0){
        for(int k=1;k<pos;k++){
            printf("%c",str[k]);
        }
    }
//指数为负,输出0.,在输出exp-1个0,输出去掉小数点的实数
    else if(str[pos+1]=='-'){
        printf("0.");
        for(int k=0;k<exp-1;k++){
            printf("0");
        }
        printf("%c",str[1]);
        for(int k=3;k<pos;k++){
            printf("%c",str[k]);
        }
    }
//指数为正,分类讨论
    else{
        int count=pos-3;//小数点后数字位数
        if(count==exp){
            printf("%c",str[1]);
            for(int k=3;k<pos;k++){
                printf("%c",str[k]);
            }
        }
        else if(exp>count){
            printf("%c",str[1]);
            for(int k=3;k<pos;k++){
                printf("%c",str[k]);
            }
            for(int k=0;k<(exp-count);k++){
                printf("0");
            }
        }
        else{
            for(int k=1;k<pos;k++){
                  if(str[k]=='.')
                   continue;
                printf("%c",str[k]);
                if(k==exp+2)
                   printf(".");
            }
        }
        return 0;
    }
}

B 1048 digital encryption

Pit: Title clear representation, not the same as the length of the string up to 0, followed by calculation; if the count to the shortest remaining contents will then copy the two test error.

A 1001 A+B Format

Nothing to say

A 1005 Spell it right

.............

A 1035 Password

................

A 1077 Kuchiguse

Seeking common suffix problem

Note that the point received the following newline use getchar () after reading n, otherwise it will lead cin.getline () to read line breaks, resulting in an error

Does not meet the conditions you want to jump out of the double loop can break (out of the inner layer cycle) + bool flag (out of the outermost loop) to achieve

for(int i=0;i<min;i++){
        char ch=array[0][i];// 取出第i个字符
        bool flag=true;
        for(int j=1;j<n;j++){
            if(array[j][i]!=ch){
               flag=false;
               break;
            }    
        }
        if(flag){
            ans++;
        }
        else
            break;
    }

A 1082 Read in Chinese

A bit complicated, to say it, wanted to change the kinds of questions.

B 1015 / A 1062 moral theory

There sort () function in #include <algorithm> header;

C ++ function call sequencing

 

 

Guess you like

Origin blog.csdn.net/kungfu_rabbit/article/details/90440150