蓝桥杯2022 第一次官方模拟赛 1-9 个人代码

参加过一次正赛,这是第一次参加所谓的模拟赛,免费的参加着玩玩。
难度比正赛简单很多很多。
做了1-4,5-9。代码如下。
第五题是最基础的二维前缀和题,这比赛写两三个小时写到最后头晕,就没写,交卷了。
其它的没对过答案,但我感觉是没有问题的。

2

138

m = [31,28,31,30,31,30,31,31,30,31,30,31]

a = 6
ans = 0
for i in range(12):
    for j in range(1,m[i]+1):
        if j == 1 or j == 11 or j == 21 or j == 31 or a%7 == 0 or a%7==6:
            ans += 1
        a+=1
print(ans)

3

91381

#include 
using namespace std;
int n;
int main(){
    double s = 0;
    int n=1;
    while(s<12){
        s += (1.0/n);
        n++;
    }
    cout<<n;
}

4

276

s = '''PHQGHUMEAYLNLFDXFIRCVSCXGGBWKFNQDUXWFNFOZVSRTKJPREPGGXRPNRVY
STMWCYSYYCQPEVIKEFFMZNIMKKASVWSRENZKYCXFXTLSGYPSFADPOOEFXZBC
OEJUVPVABOYGPOEYLFPBNPLJVRVIPYAMYEHWQNQRQPMXUJJLOOVAOWUXWHMS
NCBXCOKSFZKVATXDKNLYJYHFIXJSWNKKUFNUXXZRZBMNMGQOOKETLYHNKOAU
GZQRCDDIUTEIOJWAYYZPVSCMPSAJLFVGUBFAAOVLZYLNTRKDCPWSRTESJWHD
IZCOBZCNFWLQIJTVDWVXHRCBLDVGYLWGBUSBMBORXTLHCSMPXOHGMGNKEUFD
XOTOGBGXPEYANFETCUKEPZSHKLJUGGGEKJDQZJENPEVQGXIEPJSRDZJAZUJL
LCHHBFQMKIMWZOBIWYBXDUUNFSKSRSRTEKMQDCYZJEEUHMSRQCOZIJIPFION
EEDDPSZRNAVYMMTATBDZQSOEMUVNPPPSUACBAZUXMHECTHLEGRPUNKDMBPPW
EQTGJOPARMOWZDQYOXYTJBBHAWDYDCPRJBXPHOOHPKWQYUHRQZHNBNFUVQNQ
QLRZJPXIOGVLIEXDZUZOSRKRUSVOJBRZMWZPOWKJILEFRAAMDIGPNPUU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GINFGFRCCLMZNMJUGWWBSQFCIHUBSJOLLMSQSGHMCPH
ELSOTFLBGSFNPCUZSRUPCHYNVZHCPQUGRIWNIQXDFJPWPXFBLKPNPEELFJMT
'''
a = s.split()
cnt = 0
for i in range(1,len(a)-1):
    for j in range(1,len(a[i])-1):
        if a[i][j] < a[i-1][j] and a[i][j] < a[i+1][j] and a[i][j] < a[i][j-1] and a[i][j] < a[i][j+1]:
            cnt+=1
print(cnt)

5

6

#include 

using namespace std;

int a,b;

int main(){

    cin>>a>>b;

    cout<<a-b-1;

}

7

#include 

using namespace std;

string s;

int main(){

    cin>>s;

    for(int i=0;i<s.length();i++){

        if(s[i]=='a' || s[i]=='e' ||s[i]=='i' ||s[i]=='o' ||s[i]=='u'){

            s[i]+='A'-'a';

        }

    }

    cout<<s;

}

8

#include 
using namespace std;
int n;

int s[100];
int pretime,prea,preb;


int main(){
    cin>>n;
    char c = getchar();
    long long ans=0;
    for(int i=0;i<n;i++){
        int k=0;
        char c;
        while((c = getchar()) != '\n'){
            if(c==' ' || c==':')s[k]=-1;
            else s[k] =  int(c - '0');
            k++;
            
        }

        int a = s[9];
        for(int j=10;s[j]!=-1;j++){
            a = a*10 + s[j];
        }
        int b = s[k-1],d=1;
        for(int j=k-2;s[j]!=-1;j--){
            b += s[j]*pow(10,d);
            d++;
        }
        
        int time = (s[0]*10+s[1])*60*60 + (s[3]*10+s[4])*60 + (s[6]*10+s[7]);

        if(i!=0){
            ans+=(time-pretime)*prea*preb;
        }
        pretime = time;
        prea = a;
        preb = b;
    }
    cout<<ans;
}

9

#include 
using namespace std;
int n,m;

char g[100][100];
int di[][2] = {{1,1},{1,-1},{-1,1},{-1,-1}};

int k[][2] = {{1,-1},{1,1},{-1,-1},{-1,1}};



int search(int a,int b){
    char c = g[a][b];
    int cnt = 0 ;
    for(int d=0;d<4;d++){
        int x = a+(di[d][0]), y = b+(di[d][1]);
        while(x>=0 && x<n && y>=0 && y<m){
            if(g[x][b]==c && g[a][y]==c){
                int ok = 1,p=a,q=y;
                while(p!=x){
                    p+=k[d][0],q+=k[d][1];
                    if(g[p][q]!=c)ok=0;
                }
                if(ok==1)cnt++;
                x += (di[d][0]), y += (di[d][1]);
            }else break;
        }
    }

    return cnt;
}


int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            cin>>g[i][j];
        }
    long long ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans += search(i,j);
            //cout<
        }
        //cout<
    }

    cout<<ans;
}

你可能感兴趣的:(蓝桥杯,算法,职场和发展)