自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(78)
  • 收藏
  • 关注

原创 JS实现发布/订阅

JS实现发布订阅

2022-09-17 21:00:28 1072 1

原创 获取字符串的像素长度

获取字符串的像素长度该方法是通过正则来实现的,其中str参数是要测的字符串,font_size是字符串的字体大小,返回的就是字符串的像素长度了。const getLenPx=(str:string, font_size:number) =>{ let str_leng = str.replace(/[^\x00-\xff]/gi, 'aa').length; return str_leng * font_size / 2}该方法可以用在根据字符串的长度的不同来进行不同的显示。

2022-03-11 17:21:25 1331

原创 使用useHistory().listen监听路由变化

使用useHistory().listen监听路由变化在使用react的函数组件时,有时候我们会想监听路由变化,并在路由变化时进行某些操作,就需要使用useHistory().listen来实现了。下面是使用方法const history = useHistory();useEffect(() => { const unlisten = history.listen((historyLocation) => { cnosole.log(historyLocatio

2022-03-11 10:35:17 5688 1

原创 使用Umi的history向子页面传递数据

在Umi官方文档中,给出了两种跳转页面的方式,这篇文章主要讲解使用history的方法进行跳转和传参的操作。先给出代码路由部分(.umirc.ts):import { defineConfig } from 'umi';export default defineConfig({ nodeModulesTransform: { type: 'none', }, routes: [ { path: '/', component: '@/pages/index' }, //

2021-08-25 16:10:33 7735

原创 对useMemo使用的理解,以及与useEffect的区别

对useMemo的理解下面这个例子是想在页面上实时的显示出expensive函数的计算结果,但按照之前的写法,useState中任意的值发生改变时,页面都会重新渲染,导致昂贵的计算函数expensive会进行多余计算。这个例子中无论是val还是count发生改变,函数都会运算一遍,但我们只想在count的值发生改变时才进行这个昂贵计算,因此就要用到useMemo。import React, { useState, useMemo } from "react";export default func

2021-08-17 15:42:39 2782

原创 EOJ-2848. 华师大卫星照片

EOJ-2848. 华师大卫星照片思路:用深度算法递归#include <iostream>#include <cmath>#include <algorithm>using namespace std;int w,h;char c[1010][1010]={};int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};//位移函数int DFS(int i,int j){ if(c[i][j]=='.')return

2021-03-11 23:45:59 153

原创 A1052 Linked List Sorting (25 分)

A1052 Linked List Sorting (25 分)#include <string>#include <iostream>#include <math.h>#include <algorithm>using namespace std;struct hello{ int add,date,next,x;}p[100000];bool cmp(hello a,hello b){ if(a.x==0||b.x==0

2021-03-03 11:43:08 87 1

原创 A1032 Sharing (25 分)

A1032 Sharing (25 分)#include <iostream>#include <algorithm>using namespace std;struct hello{ char data; int next; int flag;}node[100000];int main(){ int d1,d2,dd,n,i,p; cin>>d1>>d2>>n; for(i=0

2021-03-01 18:46:41 69

原创 A1060 Are They Equal (25 分)

A1060 Are They Equal (25 分)#include <string>#include <iostream>#include <math.h>#include <algorithm>using namespace std;int n;string deal(string a,int &e){ int k=0; string b; while(a.size()>0&&a[0]

2021-02-25 16:15:39 52

原创 A1059 Prime Factors (25 分)

A1059 Prime Factors (25 分)重点:1.建立素数的初始数组,方便后面枚举2.一般一个数的因子都是小于其平方根的,如果有大于平方根的因子,也只存在一个#include <iostream>#include <math.h>using namespace std;const int maxn=1000000;int su[maxn],Count=0;bool p[maxn]={0};void find(){//创建素数数组 for(in

2021-02-24 19:16:58 79

原创 B1013 数素数 (20 分)

B1013 数素数 (20 分)#include <iostream>using namespace std;const int maxn=1000000;int su[maxn],Count=0;//用来存储素数和记录素数的个数bool p[maxn]={0};//来判断当前数是否为素数void find(){//寻找素数的函数 for(int i=2;i<maxn;i++){ if(p[i]==false){//如果i为素数

2021-02-24 17:02:53 79

原创 B1019/A1069 数字黑洞 (20 分)

B1019/A1069 数字黑洞 (20 分)给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的 6174,这个神奇的数字也叫 Kaprekar 常数。例如,我们从6767开始,将得到7766 - 6677 = 10899810 - 0189 = 96219621 - 1269 = 83528532 - 2358 = 61747641 -

2021-02-24 14:28:06 102

原创 B1040/A1093 有几个PAT (25 分)

B1040/A1093 有几个PAT (25 分)字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位§,第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位§,第 4 位(A),第 6 位(T)。现给定字符串,问一共可以形成多少个 PAT?输入格式:输入只有一行,包含一个字符串,长度不超过10^5​​ ,只包含 P、A、T 三种字母。输出格式:在一行中输出给定字符串中包含多少个 PAT。由于结果可能比较大,只输出对 1000000007 取余数的结果。

2021-02-23 22:14:08 88

原创 B-1023 组个最小数 (20 分)

B-1023 组个最小数 (20 分)给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558。现给定数字,请编写程序输出能够组成的最小的数。输入格式:输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0、数字 1、……数字 9 的个数。整数间用一个空格分隔。10 个数字的总个数不超过 50,且至少拥有 1 个非 0 的数字。输

2021-02-20 19:36:07 84

原创 B-1020 月饼 (25 分)

B-1020 月饼 (25 分)月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月饼,获得 72 + 45/2

2021-02-20 18:17:09 75

原创 A-1025 PAT Ranking (25 分)

A-1025 PAT Ranking (25 分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately afte

2021-02-08 16:21:41 154

原创 6-10 阶乘计算升级版 (20 分)

6-10 阶乘计算升级版 (20 分)本题要求实现一个打印非负整数阶乘的函数。函数接口定义:void Print_Factorial ( const int N );其中N是用户传入的参数,其值不超过1000。如果N是非负整数,则该函数必须在一行中打印出N!的值,否则打印“Invalid input”。裁判测试程序样例:#include <stdio.h>void Print_Factorial ( const int N );int main(){ int N;

2021-02-08 14:14:14 120

原创 A-1012 The Best Rank (25 分)

A-1012 The Best Rank (25 分)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we e

2021-02-07 11:11:32 81

原创 B-1015/A-1062 德才论 (25 分)

B-1015/A-1062 德才论 (25 分)宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第一行给出 3 个正整数,分别为:N(≤10^​5​​ ),即考生总数;L(≥60),为录取最低分数线,即德分和才分均不低于 L 的考生才有资格被考虑录取;H(<100),为优先录取线—

2021-02-06 15:38:53 113 2

原创 A-1082 Read Number in Chinese (25 分)

A-1082 Read Number in Chinese (25 分)Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan liu Q

2021-02-04 14:08:38 90

原创 A-1077 Kuchiguse (20 分)

A-1077 Kuchiguse (20 分)The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. Such a preference is called “Kuchiguse” and is often exagger

2021-02-03 21:14:58 100 1

原创 A-1035 Password (20 分)

A-1035 Password (20 分)To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O

2021-02-03 20:08:39 227

原创 A-1005 Spell It Right (20 分)

A-1005 Spell It Right (20 分)Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each case occupies one line whic

2021-02-03 18:58:34 62

原创 A-1001 A+B Format (20 分)

A-1001 A+B Format (20 分)Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input file contains one test case. Each

2021-02-02 21:24:30 86

原创 B-1048 数字加密 (20 分)

B-1048 数字加密 (20 分)本题要求实现一种数字加密方法。首先固定一个加密用正整数 A,对任一正整数 B,将其每 1 位数字与 A 的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对 13 取余——这里用 J 代表 10、Q 代表 11、K 代表 12;对偶数位,用 B 的数字减去 A 的数字,若结果为负数,则再加 10。这里令个位为第 1 位。输入格式:输入在一行中依次给出 A 和 B,均为不超过 100 位的正整数,其间以空格分隔。输出格式:在一行中输出加密后的结果。输入

2021-02-02 20:05:23 111

原创 B-1024/A-1073 科学计数法 (20分)

B-1024/A-1073 科学计数法 (20分)科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [±][1-9].[0-9]+E[±][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指数部分的正负号即使对正数也必定明确给出。现以科学计数法的格式给出实数 A,请编写程序按普通数字表示法输出 A,并保证所有有效位都被保留。输入格式:每个输入包含 1 个测试用例,即一个以科学计数法表示的实数 A。该数字的存储长度不超过 9999 字节,且其指数

2021-02-02 15:45:40 95

原创 B-1014/A-1061 福尔摩斯的约会 (20分)

B-1014/A-1061 福尔摩斯的约会 (20分)大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间星期四 14:04,因为前面两字符串中第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 D,代表星期四;第 2 对相同的字符是 E ,那是第 5 个英文字母,代表一天里的第 14 个钟头(于是一天的 0 点到 23

2021-02-02 14:06:19 64

原创 A-1027 Colors in Mars (20分)

A-1027 Colors in Mars (20分)People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last

2021-02-01 21:15:43 81

原创 B-1002 写出这个数 (20分)

B-1002 写出这个数 (20分)读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。输入格式:每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10^100​​ 。输出格式:在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。输入样例:1234567890987654321123456789输出样例:yi san wu#include <string>#include &lt

2021-02-01 19:06:50 73

原创 B-1031 查验身份证 (15分)

B-1031 查验身份证 (15分)一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:Z:0 1 2 3 4 5 6 7 8 9 10M:1 0 X 9 8 7 6 5 4 3 2现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。输入格式:输入第一

2021-02-01 18:33:53 149

原创 B-1021 个位数统计 (15分)

B-1021 个位数统计 (15分)#include <string>#include <iostream>using namespace std;int main(){ string n; int i,m; int w[10]={}; cin >> n; for(i=0;i<n.size();i++){ w[n[i]-'0']++;//此题的关键在于char字符转换为整数,可以按照ASCII码来理

2021-02-01 16:12:45 63

原创 B-1006 换个格式输出整数 (15分)

B-1006 换个格式输出整数 (15分)让我们用字母 B 来表示“百”、字母 S 表示“十”,用 12…n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234 应该被输出为 BBSSS1234,因为它有 2 个“百”、3 个“十”、以及个位的 4。输入格式:每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。输出格式:每个测试用例的输出占一行,用规定的格式输出 n。输入样例 1:234输出样例 1:BBSSS1234输

2021-02-01 14:25:48 76 1

原创 A-1058 A+B in Hogwarts (20分)

A-1058 A+B in Hogwarts (20分)#include <stdio.h>int main(){ long long p[3]={},a[3]={},c[3]={};//注意测试数据可能会使int型数溢出 long long P,A,C; scanf("%lld.%lld.%lld %lld.%lld.%lld",&p[0],&p[1],&p[2],&a[0],&a[1],&a[2]); P=

2021-02-01 12:37:46 74

原创 A-1019 General Palindromic Number (20分)

A-1019 General Palindromic Number (20分)Sample Input 1:27 2Sample Output 1:Yes1 1 0 1 1Sample Input 2:121 5Sample Output 2:No4 4 1#include <iostream>using namespace std;int main(){ int a,b,n,m,i=0,j=0; int w[100]={}; bool x;

2021-02-01 12:19:34 64

原创 B-1037 在霍格沃茨找零钱 (20分)

B-1037 在霍格沃茨找零钱 (20分)#include <stdio.h>#include <iostream>using namespace std;int main(){ int p[3]={},a[3]={},c[3]={}; int P,A,C; scanf("%d.%d.%d %d.%d.%d",&p[0],&p[1],&p[2],&a[0],&a[1],&a[2]); P=p[

2021-02-01 11:24:47 73

原创 B-1022 D进制的A+B (20分)

B-1022 D进制的A+B (20分)#include <iostream>using namespace std;int main(){ int a,b,c,d,i; int w[100]={}; cin>>a>>b>>d; c=a+b; if(c<d){//如果和小于要求的进制数,直接输出和 cout<<c; return 0; } for

2021-02-01 10:37:23 74

原创 A-1031 Hello World for U (20分)

A-1031 Hello World for U (20分)#include <iostream>using namespace std;int main(){ int n,i=0,j,a=0,b=0,n1=0,n2; char word[100]={}; while(scanf("%c",&word[i])!=EOF){ i++; } n=i; b=n+2; n2=b; while(b>0)

2021-01-31 21:31:43 62

原创 B-1027 打印沙漏 (20分)

B-1027 打印沙漏 (20分)#include <iostream>using namespace std;int main(){ int n,c,h,i=3,j,k,f,w,sum=0,s; char m; cin >> n >> m; if(n<7){//如果数量小于7,不能形成上下三角 cout<<m<<endl; cout<<n-1;

2021-01-31 20:41:53 73

原创 B-1036 跟奥巴马一起编程 (15分)

B-1036 跟奥巴马一起编程 (15分)美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014 年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!输入格式:输入在一行中给出正方形边长 N(3≤N≤20)和组成正方形边的某种字符 C,间隔一个空格。输出格式:输出由给定字符 C 画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数

2021-01-31 18:25:15 59

原创 A-1036 Boys vs Girls (25分)

A-1036 Boys vs Girls (25分)This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each input file contains one test case. Each case contains a

2021-01-31 14:45:15 74

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除