【蓝桥杯第十届省赛B】(部分详解)

本文展示了C++编程中的四个实例:计算特殊数的和,数列的动态更新,使用神经网络算法解决问题以及将年号转换为字符串。通过这些例子,作者展示了不同场景下的编程技巧和逻辑处理。
摘要由CSDN通过智能技术生成

特别数的和

#include <iostream>
#include <string>
using LL=long long;
using namespace std;

int main() {
    LL n;
    cin >> n;
    LL cnt = 0;
    for (LL i = 1; i <= n; i++) {
        string s = to_string(i);
        for (LL j = 0; j < s.size(); j++) {
            if (s[j] == '2' || s[j] == '0' || s[j] == '1' || s[j] == '9') {
                cnt += i;
                break; // 在找到符合条件的数字后退出内层循环
            }
        }
    }
    cout << cnt;
    return 0;
}

数列求值

#include <iostream>
using namespace std;
const int n=20190325;
int a[n]={0,1,1,1};
int main()
{
    
   for(int i=4;i<=n;i++)
    {
        a[i]=(a[i-1]+a[i-2]+a[i-3])%10000;
        //注意范围
    }
    cout<<a[20190324];
  // 请在此输入您的代码
  return 0;
}

组队

方法一:神经网络算法

#include <iostream>
using namespace std;
int main()
{
  cout<<500-3-1-1-3-2;
  return 0;
}

方法二:解题区cv大法(谢谢佬)

#include <iostream>
int main()
{
  // 请在此输入您的代码
  int aa[]={97,92,0,0,89,82,0,0,0,95,0,0,94,0,0,0,98,93,0,0};
  int bb[]={90,85,0,0,83,86,0,97,0,99,0,0,91,83,0,0,83,87,0,99};
  int cc[]={0,96,0,0,97,0,0,96,89,0,96,0,0,87,98,0,99,92,0,96};
  int dd[]={0,0,0,80,0,0,87,0,0,0,97,93,0,0,97,93,98,96,89,95};
  int ee[]={0,0,93,86,0,0,90,0,0,0,0,98,0,0,98,86,81,98,92,81};
  int a,b,c,d,e,n,max=0;
  for(a=1;a<20;a++){
    for(b=1;b<20;b++){
      for(c=1;c<20;c++){
        for(d=1;d<20;d++){
          for(e=1;e<20;e++){
            n=aa[a]+bb[b]+cc[c]+dd[d]+ee[e];
            if(max<=n&&a!=b&&a!=c&&a!=d&&a!=e&&b!=c&&b!=d&&b!=e&&c!=d&&c!=e&&d!=e){ max=n; }
          }
        }
      }
    }
  }
cout<<max;
return 0;
}

年号字符串

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[27];
    for (int i = 1; i <= 26; i++)
     a[i] = (char)(65+i-1);
    int x = 2019 / 26 / 26;
    int y = 2019 / 26 % 26;
    int z = 2019 % 26;
    cout << a[x] << a[y] << a[z] << endl;
    return 0;
}
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值