蓝桥杯资料

前言

这几天在准备蓝桥杯,根据我自己的情况,总结了一点模板,这个小白看看就行了,大佬勿看,都比较基础,没什么特别难的知识点。

ASCII码

十进制 DEC八进制 OCT十六进制 HEX二进制 BIN符号 SymbolHTML 实体编码中文解释 Description
330412100100001!!感叹号
340422200100010""双引号
350432300100011##井号
360442400100100$$美元符
370452500100101%%百分号
380462600100110&&
390472700100111'单引号
400502800101000((左括号
410512900101001))右括号
420522A00101010**星号
430532B00101011++加号
440542C00101100,,逗号
450552D00101101--连字号或减号
460562E00101110..句点或小数点
470572F00101111//斜杠
480603000110000000
490613100110001111
500623200110010222
510633300110011333
520643400110100444
530653500110101555
540663600110110666
550673700110111777
560703800111000888
570713900111001999
580723A00111010::冒号
590733B00111011;;分号
600743C00111100<<小于
610753D00111101==等号
620763E00111110>>大于
630773F00111111??问号
641004001000000@@电子邮件符号
651014101000001AA大写字母 A
661024201000010BB大写字母 B
671034301000011CC大写字母 C
681044401000100DD大写字母 D
691054501000101EE大写字母 E
701064601000110FF大写字母 F
711074701000111GG大写字母 G
721104801001000HH大写字母 H
731114901001001II大写字母 I
741124A01001010JJ大写字母 J
751134B01001011KK大写字母 K
761144C01001100LL大写字母 L
771154D01001101MM大写字母 M
781164E01001110NN大写字母 N
791174F01001111OO大写字母 O
801205001010000PP大写字母 P
811215101010001QQ大写字母 Q
821225201010010RR大写字母 R
831235301010011SS大写字母 S
841245401010100TT大写字母 T
851255501010101UU大写字母 U
861265601010110VV大写字母 V
871275701010111W&#087大写字母 W
881305801011000XX大写字母 X
891315901011001YY大写字母 Y
901325A01011010ZZ大写字母 Z
911335B01011011[[左中括号
921345C01011100\\反斜杠
931355D01011101]]右中括号
941365E01011110^^音调符号
951375F01011111__下划线
961406001100000``重音符
971416101100001aa小写字母 a
981426201100010bb小写字母 b
991436301100011cc小写字母 c
1001446401100100dd小写字母 d
1011456501100101ee小写字母 e
1021466601100110ff小写字母 f
1031476701100111gg小写字母 g
1041506801101000hh小写字母 h
1051516901101001ii小写字母 i
1061526A01101010jj小写字母 j
1071536B01101011kk小写字母 k
1081546C01101100ll小写字母 l
1091556D01101101mm小写字母 m
1101566E01101110nn小写字母 n
1111576F01101111oo小写字母 o
1121607001110000pp小写字母 p
1131617101110001qq小写字母 q
1141627201110010rr小写字母 r
1151637301110011ss小写字母 s
1161647401110100tt小写字母 t
1171657501110101uu小写字母 u
1181667601110110vv小写字母 v
1191677701110111ww小写字母 w
1201707801111000xx小写字母 x
1211717901111001yy小写字母 y
1221727A01111010zz小写字母 z
1231737B01111011{{左大括号
1241747C01111100||垂直线
1251757D01111101}}右大括号
1261767E01111110~~波浪号
1271777F01111111删除

月份数组

int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

判断闰年

bool isYear(int year)
{
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

将20200101转换为年月日

  int year = y / 10000;
  y = y % 10000;
  int month = y / 100;
  int day = y % 100;

检查数字是否为年月日(是否合法)

bool check_valid(int year, int month, int day)
{
    if (month == 0 || month > 12)
    {
        return false;
    }
    if (day == 0)
    {
        return false;
    }
    if (month != 2)
    {
        if (day > days[month])
        {
            return false;
        }
    }
    else
    {
        int leap = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
        if (day > days[month] + leap)
        {
            return false;
        }
    }
    return true;
}

一秒=1000毫秒

int的范围

-2^31=-21 4748 3648 到 2^31-1=21 4748 3647。共10位,21亿。

2^31=2,147,483,648 10^9数量级

将时间戳转换成时分秒

#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码
  long long int time;
  cin>>time;
  time /= 1000;
  long long int s = time % 60;
  time /= 60;
  long long int m = time % 60;
  time /= 60;
  long long int h = time % 24;
  printf("%02lld:%02lld:%02lld",h,m,s);
  return 0;
}

将时间戳转换为日期形式

#include <stdio.h>
#include <time.h>

int main()
{
    time_t t = 46800999; // 假设时间戳为2021年5月4日12点0分0秒
    struct tm *tm = localtime(&t);
    char s[64];
    strftime(s, sizeof(s), "%Y:%m:%d-%H:%M:%S", tm);
    // strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", tm);

    printf("%s\n", s);
}

精确道毫秒级别

#include <stdio.h>
#include <time.h>

int main()
{
    long long timestamp = 1649262000000; // Replace this with your timestamp
    time_t seconds = timestamp / 1000;
    struct tm *timeinfo = localtime(&seconds);
    char buffer[80];
    strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
    printf("%s.%03ld\n", buffer, timestamp % 1000);
}

判断一个字符是不是为数字的函数isdigit,将字符数字转换为数字

isdigital()如果是的话就会返回1

str[i]-‘0’:这样可以将字符转换为数字。

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(){
    string str;
    cin>>str;
    int len = str.size();
    // printf("%s %d",str,len);
    for(int i = 0 ; i < len ;i ++){
        if(isdigit(str[i]) == 1){
            int x = str[i] - '0';
            // printf("%d",x);
            for(int j = 0 ;j < x - 1 ;j ++){
                printf("%c",str[i - 1]);
            }
        }
        else{
            printf("%c",str[i]);
        }
        
    }
    
}

dbs暴搜

image-20230406090058414

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int res;
void dfs(int x , int y){
    if(x > m || y > n) return;
    if(x % 2 == 0 && y % 2 ==0) return;
    if(x == m && y == n){
        res ++;
    }
    dfs(x + 1 , y);
    dfs(x , y + 1);
}

int main(){
    cin>>n>>m;
    dfs(1,1);
    printf("%d",res);
    return 0;
}

最大公约数&最小公倍数

x*y=最小公倍数*最大公约数

辗转相除法求最大公约数:

int measure(int x, int y)
{	
	int z = y;
	while(x%y!=0)
	{
		z = x%y;
		x = y;
		y = z;	
	}
	return z;
}

gcd函数求最大公约数


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    // 使用 __gcd(int a, int b) 函数
    int a = 3, b = 9;
    cout << __gcd(a, b); // 输出的就是a与b的gcd函数
}

string字符串相关操作

size()

size()和length():返回string对象的字符个数,他们执行效果相同。

大小写转换

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s = "ABCDEFG";

    for( int i = 0; i < s.size(); i++ )
    {
        s[i] = tolower(s[i]);
    }

    cout<<s<<endl;
    return 0;
}

find()

void test8()
{
    string s("dog bird chicken bird cat");

    //字符串查找-----找到后返回首字母在字符串中的下标

    // 1. 查找一个字符串
    cout << s.find("chicken") << endl;        // 结果是:9

    // 2. 从下标为6开始找字符'i',返回找到的第一个i的下标
    cout << s.find('i',6) << endl;            // 结果是:11

    // 3. 从字符串的末尾开始查找字符串,返回的还是首字母在字符串中的下标
    cout << s.rfind("chicken") << endl;       // 结果是:9

    // 4. 从字符串的末尾开始查找字符
    cout << s.rfind('i') << endl;             // 结果是:18-------因为是从末尾开始查找,所以返回第一次找到的字符

    // 5. 在该字符串中查找第一个属于字符串s的字符
    cout << s.find_first_of("13br98") << endl;  // 结果是:4---b

    // 6. 在该字符串中查找第一个不属于字符串s的字符------先匹配dog,然后bird匹配不到,所以打印4
    cout << s.find_first_not_of("hello dog 2006") << endl; // 结果是:4
    cout << s.find_first_not_of("dog bird 2006") << endl;  // 结果是:9

    // 7. 在该字符串最后中查找第一个属于字符串s的字符
    cout << s.find_last_of("13r98") << endl;               // 结果是:19

    // 8. 在该字符串最后中查找第一个不属于字符串s的字符------先匹配t--a---c,然后空格匹配不到,所以打印21
    cout << s.find_last_not_of("teac") << endl;            // 结果是:21

}

字符排序sort()

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

void test9()
{
    string s = "cdefba";
    sort(s.begin(),s.end());
    cout<<"s:"<<s<<endl;     // 结果:abcdef
}

1MB=1024kb

1MB=1024kb

1kb=1024字节(byte)

1字节=8位(bits)

比long long int 还大的数字范围

unsigned long long int

c++中的最大值

**最大值:**0x3f3f3f3f

**最小值:**0xc0c0c0c0

前缀和

image-20230407123827144

#include<iostream>
using namespace std;
const int N = 100010;
int a[N] , s[N];
int main(){
    int n ,  m; 
/// n为数组的大小  m查询个数
    scanf("%d%d",&n,&m);
    
    // 输入数组的数值
    for(int i = 1 ;i <= n ;i++) scanf("%d",&a[i]);  //初始化数组
    
    
    //计算 数组中前缀和
    for(int i = 1 ;i <= n; i++) s[i] = s[i-1] + a[i] ;  //初始化前缀和
    
    //  
    while(m --){
        int l , r;  //定义左侧与右侧
        scanf("%d %d",&l,&r);
        printf("%d\n",s[r] - s[l-1]);
    }
        
}

将26位字符映射到0-25

string s; //存放的字符串
int count[26] ={0};	//用来记录字符串中每一个字符出现的次数
for(int i = 0 ; i < s.size() ; i++){
    int index = s[i] - 'a';
    count[index] ++;
}

相关进制转换

十进制以八进制和16进制输出

#include<iostream> 
using namespace std;
 
int main(){
	int a;
	scanf("%d",&a);
	printf("原始数据:%d \n",a);
	printf("以八进制输出:%o \n",a);
	printf("以十六进制输出:%x",a);	
	
	return 0; 
}

十进制转任何进制

//十进制转换为任意进制的源码
#include <iostream>
using namespace std;
 
int main()
{
	long n;
	int p,c,m=0,s[100];
	cout<<"输入要转换的数字:"<<endl;
	cin>>n;
	cout<<"输入要转换的进制:"<<endl;
	cin>>p;
 
	cout<<"("<<n<<")10="<<"(";
 
	while (n!=0)//数制转换,结果存入数组s[m]
	{
		c=n%p;
		n=n/p;
		m++;s[m]=c;   //将余数按顺序存入数组s[m]中
	}
 
	for(int k=m;k>=1;k--)//输出转换后的序列
	{
		if(s[k]>=10) //若为十六进制等则输出相对应的字母
			cout<<(char)(s[k]+55);
		else         //否则直接输出数字
			cout<<s[k];
	}
 
	cout<<")"<<p<<endl;
 
	return 0;
}


十进制转n进制

 void conversion(int a,int n) 
 {
 	if(a <= 0)
 	{
 		cout << 0;
 		return;
	 }
 	stack<int> aa;
 	while(a)
 	{
 		aa.push(a%n);
 		a/=n;
	 }
	 while(!aa.empty())
	 {
	 	int t = aa.top();
	 	if(t > 9)
	 	{
	 		char c = t-10 + 'A';
	 		cout << c;
		 }else
	 		cout << t ;
	 	aa.pop();
	 }
 }

十进制转二进制

//十进制转二进制
#include<iostream>
using namespace std;
 
void printbinary(const unsigned int val)
{
	for(int i = 16; i >= 0; i--)
	{
		if(val & (1 << i))
			cout << "1";
		else
			cout << "0";
	}
}
 
int main()
{
	printbinary(1024);
	return 0;
}

四舍五入

round()

相关数学函数

sqrt

image-20230407184924826

pow

返回的是double类型的

素数

#include <stdio.h>
int main() {
	int n;
	printf("请输入一个1-100之间的整数:\n");
	scanf("%d", &n);
 
 
	int m = 0;
	for (int i = 2; i < n; i++ ) {
		if(n % i  == 0) {
			m++;
		}
	}
	if (m == 0) {
		printf("%d是素数\n", n);
	} else {
		printf("%d不是素数\n", n);
	}
 
	return 0;
}

回文数

bool hws(int n)
{
	int ans=0,m=n;
	while(m>0)
	{
		ans=ans*10+m%10;
		m/=10;
	}
	return ans==n;
}

等差数列

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bEimwBn2-1681032329168)(C:\Users\陈勇\AppData\Roaming\Typora\typora-user-images\image-20230407222545633.png)]

等比数列

image-20230407222617076

快速幂

const int mod = 1e9 + 7; // (a的b次方对mod取模)
int ksm(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = res % mod * a % mod;
        a = a % mod * a % mod;
        b >>= 1;
    }
    return res;
}

);

int m = 0;
for (int i = 2; i < n; i++ ) {
	if(n % i  == 0) {
		m++;
	}
}
if (m == 0) {
	printf("%d是素数\n", n);
} else {
	printf("%d不是素数\n", n);
}

return 0;

}




# 回文数

```c++
bool hws(int n)
{
	int ans=0,m=n;
	while(m>0)
	{
		ans=ans*10+m%10;
		m/=10;
	}
	return ans==n;
}

等差数列

[外链图片转存中…(img-bEimwBn2-1681032329168)]

等比数列

[外链图片转存中…(img-tinvav5y-1681032329169)]

快速幂

const int mod = 1e9 + 7; // (a的b次方对mod取模)
int ksm(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = res % mod * a % mod;
        a = a % mod * a % mod;
        b >>= 1;
    }
    return res;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
蓝桥杯的Scratch资料是为参加蓝桥杯编程大赛的学生们提供的一种学习和教学工具。Scratch是一种可视化的编程语言,它的界面简洁友好,适合初学者入门。 蓝桥杯的Scratch资料包括了一系列教程、范例和实战题目。教程以简洁明了的方式介绍了Scratch的基本概念和操作方法。通过学习教程,学生们可以掌握Scratch的编程基础,了解如何创建和操控角色,如何运用各种代码块来实现功能。 范例是一些已经完成的Scratch项目,可以供学生们参考和借鉴。范例项目涵盖了不同的主题,例如游戏、动画和交互式应用等。学生们可以通过观察和研究范例项目,了解Scratch编程的实际应用和技巧,提升自己的编程能力。 实战题目是针对蓝桥杯的比赛要求设计的编程任务。这些题目既有简单的入门题,也有复杂的挑战题。学生们可以通过解答这些题目,锻炼自己的逻辑思维和问题解决能力,提升在比赛中的竞争力。 蓝桥杯的Scratch资料不仅提供了学习和教学的工具,还培养了学生们的创造力和团队合作精神。学生可以根据自己的兴趣和创意,设计和开发自己的项目。同时,Scratch还支持多人协作,学生们可以和同学们一起共同完成一个项目,提升团队协作和沟通能力。 总之,蓝桥杯的Scratch资料是一套全面的教学资料,帮助学生们掌握Scratch编程知识和技巧,提升编程能力,并为参加蓝桥杯编程大赛奠定坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值