蓝桥杯 入门----普及-

[蓝桥杯 2020 省 AB1] 解码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 string s;
 4 char ch;
 5 int x,res;
 6 int main()
 7 {
 8     cin>>s;
 9     for(int i=0;i<s.size();i++)
10     {
11         if(s[i]<='0'||s[i]>'9')
12         {
13             if(s[i+1]<='0'||s[i+1]>'9') {cout<<s[i];continue;}
14             else if(s[i+1]>='0'&&s[i+1]<='9')
15             {
16                 res=s[i+1]-'0';
17                 for(int j=0;j<res;j++) cout<<s[i];
18                 i++;
19             }
20         } 
21     }
22     return 0;
23 }

[蓝桥杯 2013 省 AB] 错误票据

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e6+10;
 4 long long n,a[N],res,ans,m;
 5 bool vis[N],f,p;
 6 int main()
 7 {
 8     cin>>n;
 9     while(cin>>a[m]) m++;
10     sort(a,a+m);
11     //cout<<m<<endl;
12     for(int i=0;i<m;i++)
13     {
14         if(a[i]+1<a[i+1]&&!f) res=a[i]+1,f=true;//注意这里不能是!=,必须是小于
15         if(a[i]==a[i+1]&&!p) ans=a[i],p=true;
16         if(ans!=0&&res!=0) break;
17    // cout<<a[i]<<' ';
18     }
19     cout<<res<<" "<<ans;
20     return 0;
21 }

[蓝桥杯 2015 省 A] 饮料换购

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+10;
 4 int n,res,x,rest,m;
 5 int main()
 6 {
 7     cin>>n;
 8     n*=3;//将所有的全部变成瓶盖来算
 9     while(n>=3)
10     {
11         res+=n/3;
12         n=n/3+n%3;
13     }
14     cout<<res;
15     return 0;
16 }

[蓝桥杯 2018 省 A] 航班时间

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int t;
 6     cin>>t;
 7     while(t--)
 8     {
 9         int x[2]={0};
10         for(int i=0;i<2;i++)
11        {
12          int h1,h2,m1,m2,s1,s2,d=0;
13         scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
14         if(getchar()==' ') scanf("(+%d)",&d);
15         x[i]=(d*86400+h2*3600+m2*60+s2)-(h1*3600+m1*60+s1);
16        }
17        int ans=(x[0]+x[1])/2;
18        printf("%02d:%02d:%02d\n",ans/3600,ans%3600/60,ans%60);
19 
20     }
21     return 0;
22 }

[蓝桥杯 2021 省 B] 时间显示

1 #include<bits/stdc++.h>
2 using namespace std;
3 long long t,hh,ss,mm;
4 int main()
5 {
6     cin>>t;
7     hh=(t/3600000)%24,mm=(t/60000)%60,ss=(t/1000)%60;
8     printf("%02lld:%02lld:%02lld",hh,mm,ss);
9 }

[蓝桥杯 2018 省 B] 螺旋折线

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 long long  x,y,res,p;
 4 int main()
 5 {
 6     cin>>x>>y;
 7     p=max(abs(x),abs(y));
 8     if(x>=0&&y>=0) res=(p+p)*(p+p),res-=(p-x),res+=(p-y);//第一象限
 9     if(x<=0&&y>=0) res=(p+p)*(p+p),res-=p-x,res-=p-y;//第二象限
10     if(x>=0&&y<=0) res=(p+p)*(p+p),res+=p-x,res+=p-y;//第四象限
11     if(x<=0&&y<=0){//第三象限,最难处理的点
12         if(abs(y)>=abs(x)) res=(p*2)*(p*2+1),res+=p-x;//如果y比x要大,就从第四象限开始搜,向左横推
13         else res=(p*2)*(p*2-1),res-=p-y;//否则就是从第二象限开始向下推
14     }
15     cout<<res;
16     return 0;
17 }

 

posted @ 2023-06-06 16:42  o-Sakurajimamai-o  阅读(66)  评论(0)    收藏  举报
-- --