当前位置:网站首页>LCP 17. Quick Calculation Robot
LCP 17. Quick Calculation Robot
2022-08-04 05:35:00 【先生高】
LCP 17. Quick Calculation Robot
Xiaokou found a quick calculation robot at the autumn market.The store owner says two numbers (denoted as x and y) to the robot, please give the calculation instruction:
"A" operation: make x = 2 * x + y;"B" operation: make y = 2 * y + x.
In this game, the numbers spoken by the store owner are x = 1 and y = 0, and the calculation instructions spoken by Xiaokou are recorded as a string s consisting of capital letters A and B only.order indicates the calculation order, please return what the final sum of x and y is.
Example 1:
input: s = "AB"output: 4explain:After one A operation, x = 2, y = 0.After another B operation, x = 2, y = 2.The final sum of x and y is 4.
This problem is actually very simple. The code to solve the problem is as follows:
int fA(int x,int y){return 2*x+y;}int fB(int x,int y){return 2*y+x;}int calculate(char* s){int i;int x=1,y=0;for(i=0;s[i]!='\0';i++){if(s[i]='A')span>{x=fA(x,y);}else{y=fB(x,y);}}return x+y;}
边栏推荐
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
- Web Basics and Exercises for C1 Certification - My Study Notes
- 8.03 Day34---BaseMapper查询语句用法
- 解决安装nbextensions后使用Jupyter Notebook时出现template_paths相关错误的问题
- About yolo7 and gpu
- MySQL log articles, binlog log of MySQL log, detailed explanation of binlog log
- OpenRefine开源数据清洗软件的GREL语言
- 数的划分之动态规划
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
- 9、动态SQL
猜你喜欢
npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa
使用Loadrunner进行性能测试
el-Select selector bottom fixed
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器
应届生软件测试薪资大概多少?
TensorRT例程解读之语义分割demo
解决错误:npm WARN config global `--global`, `--local` are deprecated
C1认证之web基础知识及习题——我的学习笔记
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
随机推荐
7.13 Day20----MYSQL
The symbol table
8.03 Day34---BaseMapper查询语句用法
梳理CamStyle、PTGAN、SPGAN、StarGAN
MySql data recovery method personal summary
4.2 Declarative Transaction Concept
处理List<Map<String, String>>类型
代码重构:面向单元测试
Embedded system driver primary [3] - _IO model in character device driver foundation
文献管理工具 | Zotero
Get the selected content of the radio box
Canal mysql data synchronization
Write golang simple C2 remote control based on gRPC
Cannot read properties of null (reading ‘insertBefore‘)
12. Paging plugin
OpenSSF 安全计划:SBOM 将驱动软件供应链安全
Gartner 权威预测未来4年网络安全的8大发展趋势
Sublime Text 3 2021.8.3 个人配置
如何低成本修bug?测试左移给你答案
Landing, the IFC, GFC, FFC concept, layout rules, forming method, use is analysed