PAT (Advanced Level) Practice

PAT (Advanced Level) Practice python解法合集 1001 A+B Format 1002 A+B for Polynomials 1003 Emergency 1004 Counting Leaves 1005 Spell It Right 1006 Sign In and Sign Out 1007 Maximum Subsequence Sum 1008 Elevator 1009 Product of Polynomials 1010 R... 阅读详情

A+B Format

#include <bits/stdc++.h>
using namespace std;

int integer1, integer2, numOfDigits, flag;

void scanAndAdd();
void isNegativeAndPrintSymbol();
void calculateNumOfDigits();
void determineFlag();
void print();

int main()
{
	scanAndAdd();
	isNegativeAndPrintSymbol();
	calculateNumOfDigits();
	determineFlag();
	print();
	return 0;
}

/* 1、处理输入并做加运算
2、判断是否为负数,若是则先输出负号并且取绝对值
3、判断该整数是几位数
4、设置一个标志变量,用来判断当前是否应该输出逗号,根据整数位数判断标志变量的初值
5、利用循环,从高位向低位,依次输出每一位的数值 */

void scanAndAdd() // 1、处理输入并做加运算
{
	scanf("%d %d", &integer1, &integer2);
	integer1 += integer2;
	// printf("integer1 = %d\n", integer1);
}

void isNegativeAndPrintSymbol() // 2、判断是否为负数,若是则先输出负号并且取绝对值
{
	if (integer1 < 0)
	{
		printf("-");
		integer1 = abs(integer1);
	}
}

void calculateNumOfDigits() // 3、判断该整数是几位数
{
	numOfDigits = 0;
	int temp = integer1;
	while (temp)
	{
		temp /= 10;
		++numOfDigits;
	}
	if (!integer1)
	{
		numOfDigits = 1;
	}
	// printf("numOfDigits = %d\n", numOfDigits);
}

void determineFlag() // 4、设置一个标志变量,用来判断当前是否应该输出逗号,根据整数位数判断标志变量的初值
{
	flag = numOfDigits % 3;
}

void print() // 5、利用循环,从高位向低位,依次输出每一位的数值
{
	int temp = pow(10, numOfDigits - 1);
	while (temp)
	{
		if (!flag)
		{
			flag = 3;
		}
		int digit = integer1 / temp;
		printf("%d", digit);
		--flag;
		integer1 %= temp;
		temp /= 10;
		if (!flag && temp)
		{
			printf(",");
		}
	}
}

A+B for Polynomials

#include <bits/stdc++.h>
using namespace std;

/* 1、map的erase用法(段错误) */

map<int, double, greater<int>> terms; //存放多项式的每一个项,键为指数,值为系数
int ka, kb;							  // A、B的项数

void copeWithPolynomialA();
void copeWithPolynomialB();
void copeWithTerms();
void print();

int main()
{
	/* 	map<int, int> m;
		m[3] = 2;
		m[4] = 3;
		m[2] = 7;
		m[0] = 10;
		m[11] = 1;
		m[12] = 12;
		m[0] = 2;
		for (auto a : m)
		{
			printf("%d %d\n", a.first, a.second);
		}
		printf("After erase\n");
		for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it)
		{
			if (it->second == 2)
			{
				m.erase(it++->first);
			}
		}
		for (auto a : m)
		{
			printf("%d %d\n", a.first, a.second);
		}  */
	copeWithPolynomialA();
	copeWithPolynomialB();
	//copeWithTerms();
	print();
	return 0;
}

void copeWithPolynomialA()
{
	scanf("%d", &ka);
	for (int i = 0; i < ka; ++i)
	{
		// exponents and coefficients
		int exp;
		double coe;
		scanf("%d %lf", &exp, &coe);
		terms[exp] = coe;
	}
	/* //debug
	for (auto a : terms)
	{
		printf("%d %.1lf\n", a.first, a.second);
	} */
}

void copeWithPolynomialB()
{
	scanf("%d", &kb);
	for (int i = 0; i < kb; ++i)
	{
		// exponents and coefficients
		int exp;
		double coe;
		scanf("%d %lf", &exp, &coe);
		terms[exp] += coe;
		if (!terms[exp])
		{
			terms.erase(exp);
		}
	}
	/* // debug
	for (auto a : terms)
	{
		printf("%d %.1lf\n", a.first, a.second);
	} */
}

void copeWithTerms()
{
	if (terms.size())
	{
		for (map<int, double>::iterator it = terms.begin(); it != terms.end(); ++it)
		{
			if (it->second == 0)
			{
				terms.erase(it++->first);
			}
		}
	}
	/*
	 // debug
	 for (auto a : terms)
	 {
		 printf("%d %.1lf\n", a.first, a.second);
	 } */
}

void print()
{
	printf("%d", terms.size());
	if (terms.size())
	{
		for (map<int, double>::iterator it = terms.begin(); it != terms.end(); ++it)
		{
			printf(" %d %.1lf", it->first, it->second);
		}
		/* for (auto a : terms)
		{
			printf(" %d %.1lf", a.first, a.second);
		} */
	}
}

 调试过程中出现了段错误以及运行超时,其原因都是map的erase函数使用不当,上网查了一些资料,说是在erase一个记录的时候,系统会把相应的寄存器也删除?然后程序就会出现问题。

上述问题在循环外erase时应该不会发现异常,但是当erase函数是在循环内调用时,就会出现错误了。

现在太饿了,要去吃饭,所以循环内erase的使用方法还没搞懂,循环外erase可以放心大胆地使用。

时隔许久,才想起来这道题,发现第一次做的时候把这事想的太复杂了,我都没耐心看自己之前写的程序了,所以就重新写了一下,AC如下。 

#include <bits/stdc++.h>
using namespace std;
int main()
{
    double zhi_xi[1001] = {0};
    int N = 0;
    int sumOfXiangShu = 0;
    scanf("%d", &N);
    sumOfXiangShu = N;
    while (N--)
    {
        int zhishu = 0;
        double xishu = 0;
        scanf("%d %lf", &zhishu, &xishu);
        zhi_xi[zhishu] = xishu;
    }
    scanf("%d", &N);
    while (N--)
    {
        int zhishu = 0;
        double xishu = 0;
        scanf("%d %lf", &zhishu, &xishu);
        if (zhi_xi[zhishu])
        {
            zhi_xi[zhishu] += xishu;
            if (zhi_xi[zhishu])
            {
                continue;
            }
            else
            {
                sumOfXiangShu--;
            }
        }
        else
        {
            zhi_xi[zhishu] = xishu;
            sumOfXiangShu++;
        }
    }
    printf("%d", sumOfXiangShu);
    for (int i = 1000; i >= 0; --i)
    {
        if (zhi_xi[i])
        {
            printf(" %d %.1lf", i, zhi_xi[i]);
        }
        else
        {
            continue;
        }
    }
    return 0;
}

carsim与simulink联合仿真学习笔记(二)——使用C-class车模做driver model仿真(5 driver sensors) Driver model 在carsim的Simulink库中自带外部驾驶员模型,打开后如图所示: 然后打开carsim中对应的数据集,如图所示: 具体仿真步骤不在赘述,注意到这里选择的是E-Class车模,那么如果我想选择C-Class车型进行仿真呢?点三角选择车型可以看到: 马赛克部分是我后来建的,如过没有使用过是没有马赛克部分的。那么既然这里没有C-class,又该怎么办呢? 创建C-... 阅读详情

相关推荐

matinal:S4 HANA 详解ACDOCA与BSEG的区别都在这了

当你在Coding Block中添加自定义字段的时候

matinal 當冬夜漸暖 。公众号:matinal 4571

PAT (Advanced Level) Practice 1001 A+B Format

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).

XMD20030525的博客 1676

hi3519dv500 os04a10输入调试

因该sensor接在soc端的iic6,在驱动中(Hi3519DV500_SDK_V2.0.1.1\smp\a55_linux\source\mpp\cbb\isp\user\sensor\hi3519dv500\omnivision_os04a10\os04a10_sensor_ctl.c)注意总线的选择。mem_process_isolation=1 改为 mem_process_isolation=0。2、OT_MIPI_SET_HS_MODE配置为LANE_DIVIDE_MODE_1。

linus 3164

PAT ( Advanced Level ) Practice——攒够一波

exponents 指数 coefficients 系数 polynomials 多项式 // 1001 #include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int main() { int a, b; cin>>a>>b; int ans = a + b; int f = 0; if (ans == 0) { cout<&l.

Coco_T的博客 1140

VUE3如何使得大屏自适应的几种方法?

16:9。

weixin_42711805的博客 1万+

RoboMaster机甲大师赛备赛:如何用STM32+CAN总线精准控制四个大疆3508电机?

本文详细介绍了在RoboMaster机甲大师赛中,如何利用STM32和CAN总线技术精准控制四台大疆3508电机。从硬件架构设计、多电机ID分配、数据解析到同步控制算法,全面解析了构建高响应、低延迟底盘驱动系统的关键技术,助力参赛队伍提升机器人运动性能。

weixin_28684825的博客 133

PAT甲级(Advanced Level) Practice 1008 Elevator

3 2 3 141。

2301_78006009的博客 581

C#+Winform+OpenCvSharp实战:5步搞定工业视觉检测框架(附源码下载)

本文详细介绍了如何使用C#、Winform和OpenCvSharp构建工业视觉检测框架,通过5个关键步骤实现高效、稳定的视觉检测系统。内容涵盖环境配置、相机集成、核心算法实现、系统集成与通信,以及部署优化,帮助开发者快速掌握工业视觉检测技术,提升检测精度和效率。附完整源码下载,助力工业数字化转型。

pz89012345的博客 550

PAT (Advanced Level) Practice 题目集合(1051 ~ 1100)

1051 Pop Sequence (25 分) #include<bits/stdc++.h> using namespace std; const int N = 1e5+10; int n, m, k; int a[N], b[N]; int main() { cin >> m >> n >> k; for (int i = 1;i <= n;i ++) a[i] = i; while (k --) { stack <int&gt

LJR的博客 5257

64、5G 侧链通信技术详解

本文详细解析了5G侧链通信的关键技术,包括资源感知与选择、UE间协调、混合ARQ、功率控制、信道探测与CSI报告以及侧链同步。资源感知与选择通过周期性或随机方式实现资源分配,UE间协调通过主动或被动方式避免资源冲突。混合ARQ机制确保数据传输可靠性,功率控制和信道探测优化传输质量并减少干扰。侧链同步则通过多种方式确保设备间时间一致性。这些技术相互配合,构建了高效稳定的5G侧链通信体系,适用于智能交通、物联网、应急通信等多个领域,为未来无线通信发展提供强大支撑。

oil88的博客 100

25、格式化字符串攻击全解析

本文深入解析了格式化字符串攻击的原理与利用方式,涵盖缓冲区溢出与格式化字符串漏洞的区别,详细介绍了printf函数的工作机制、常见格式化说明符及其安全隐患。文章分析了三类典型编程错误导致的漏洞,并展示了如何通过恶意格式化字符串实现拒绝服务、内存读取和写入攻击。同时,提供了有效的防御措施,包括输入验证、使用安全函数、避免直接使用用户输入作为格式化字符串以及启用编译器安全选项,帮助开发者防范此类高危漏洞。

beer8的博客 83

PAT (Advanced Level) Practice 题解代码 - III (1101-1150)

PAT (Advanced Level) Practice 题解代码 - III (1101-1150)

weixin_41801682的博客 1万+

ABAP链接外围数据库SQL实战案例

这是一个ABAP 直接读取SQL数据库数据的实例,以此种方式可以将SAP与外围的系统做一些集成,比如生产,SAP本身生产这部分是弱项,管不了那么细,很多车间的数据都是在MES系统,如管理上需要则可以将MES的一些数据自动读取过来,结合SAP本身的业务数据,做一些分析是比较方便的。 1、首先在SAP里建立数据库链接:DBCO ,直接增加一条记录,填上数据库的相关信息:IP地址、数据库名、账号SA、密码这些。 2、开发程序,设置成自动运行的计划,固定时间自动读取SQL里的数据,保存到SAP自定义表.

heng0757的专栏 1511

PAT (Advanced Level) Practice 1103

PAT (Advanced Level) Practice 1103 原题链接 1. 题目大意 给出三个正数N,P,KN,P,KN,P,K,其中范围分别是 N≤400,K≤N,1<P≤7N\leq400,K\leq{N},1<P\leq7N≤400,K≤N,1<P≤7 找出满足下列条件的序列,n[1]…n[K]n[1]…n[K]n[1]…n[K] N=n[1]P+...n[K]PN = n[1]^P + ... n[K]^PN=n[1]P+...n[K]P 多组解保证max(n[1]+…

flashkiller2的博客 156

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

PAT (Advanced Level) Practice(更新中)

Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性表:栈,队列,链表,顺序表 树:二叉树的建立和遍历,完全二叉树,二叉查找树,平衡二叉树,堆,哈夫曼树 图:图的存储和遍历 经典高级算法: 深度...

weixin_33985679的博客 300

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

PAT (Advanced Level) Practice 1101~1120

文章目录11011102110311041105110611071108110911101111111211131114111511161117111811191120 1101 1102 1103 1104 一道纯考察数学规律的题目。 第 i 个数 a b c d 在长度为1的片段中出现的次数 1 1 1 1 在长度为2的片段中出现的次数 1 2 2 1 在长度为3的片段中出现的次数 1 2 2 1 在长度为4的片段中出现的次数 1 1 1 1 总计出现次数 4 6

张小艾博客 959

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of sign

lingchen1120的博客 220

PAT (Advanced Level) Practice 1031 Hello World for U

题目:PAT (Advanced Level) Practice 1031 Hello World for U (20 point(s)) 题目大意思就是给一个字符串,然后输出该字符串,使得输出的形状是U形的。具体的关系说明请看解题思路。 解题思路 首先根据题目给出的条件 n1{n_1}n1​表示左边的一列有几个字符,n2{n_2}n2​表示最下面的一行有几个字符,n3{n_3}n3​表示最右边的一列有几个字符。其中满足关系n1=n3<=max{k∣k<n2,3<=n2<=N}

helloful的博客 164

PAT (Advanced Level) Practice 1021~1040

PAT Advanced Level Practice 解题思路和代码,主要用的是 C++。每22题一篇博客,可以按目录来进行寻找。

张小艾博客 1123

PAT (Advanced Level) Practice 1051 Pop Sequence (25 分) 凌宸1642

PAT (Advanced Level) Practice 1051 Pop Sequence (25 分) 凌宸1642 题目描述: Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop

lingchen1120的博客 265

PAT (Advanced Level) Practice 1009

1009 Product of Polynomials (25分) 题目自行查看浙大PTA 甲级(English)1009,我将它和PTA 甲级 1002 归为一类,1002题解在博文已给出 题目为简单模拟,难度不大,此处提供两种思路,编译器是g++ 6.5.0,C++编译器,头文件包含cstdio(不推荐写stdio.h) 个人擅长用C解题,过程中习惯用scanf和printf而不是cin 和 cout(速度上前两者快得多) 题解1 #include <cstdio&g

DevXU的博客 1844

PAT (Advanced Level) Practice 1087 All Roads Lead to Rome (30 分) 凌宸1642

PAT (Advanced Level) Practice 1087 All Roads Lead to Rome (30 分) 凌宸1642 题目描述: Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness. 译:实际

lingchen1120的博客 680

PAT (Advanced Level) Practice 1075 PAT Judge

一、概述 写一个模仿PAT的算法计算总分的程序。 挺麻烦的,和考场问题差不多。总分排序加上各人各题排序。 两个排序之后还有几个坑: 这样的人是不会输出的:没有过submit的人,sub了但是没有编译通过的人。 为了把这样的人摘出去,我们需要使用两个旗语,分别计算sub数和编译成功数。 都不为0才输出。 第二个坑是只要有sub,那么即使编译未通过,该题分数也是0而不是-,这一点要注意。...

四轩茶屋 216

PAT (Advanced Level) Practice 1095 Cars on Campus (30 分)

PAT (Advanced Level) Practice 1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you

太空没有鹿的博客 1052

PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642

PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: 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). 译:计算 a + b 的和,并格式化输出——即

lingchen1120的博客 186
上一篇: 数据库openGauss基本使用
下一篇: EBP寄存器
6eanut
博客等级 码龄6年 646粉丝 111原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

6eanut

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值