当前位置:网站首页>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;} 边栏推荐
- 9. Dynamic SQL
- 7、特殊SQL的执行
- 8.03 Day34---BaseMapper query statement usage
- Programming hodgepodge (4)
- Web Basics and Exercises for C1 Certification - My Study Notes
- 4.2 Declarative Transaction Concept
- C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
- JS基础--强制类型转换(易错点,自用)
- SLSA 框架与软件供应链安全防护
- The symbol table
猜你喜欢

4.3 Annotation-based declarative transactions and XML-based declarative transactions

3面头条,花7天整理了面试题和学习笔记,已正式入职半个月
![[Cocos 3.5.2]开启模型合批](/img/d9/9e8f71c9a26c8052b11291fe3ba7ac.png)
[Cocos 3.5.2]开启模型合批

字节最爱问的智力题,你会几道?

你以为border-radius只是圆角吗?【各种角度】

The difference between px, em, and rem

8、自定义映射resultMap

Grain Mall - Basics (Project Introduction & Project Construction)

嵌入式系统驱动初级【3】——字符设备驱动基础中_IO模型

The symbol table
随机推荐
Cannot read properties of null (reading 'insertBefore')
触觉智能分享-SSD20X实现升级显示进度条
C1认证之web基础知识及习题——我的学习笔记
C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
TSF微服务治理实战系列(一)——治理蓝图
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
canal实现mysql数据同步
解决安装nbextensions后使用Jupyter Notebook时出现template_paths相关错误的问题
12. Paging plugin
OpenRefine中的正则表达式
Get the selected content of the radio box
Cannot read properties of null (reading ‘insertBefore‘)
8、自定义映射resultMap
Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用
8款最佳实践,保护你的 IaC 安全!
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.1 Arrays are not pointers
Write golang simple C2 remote control based on gRPC
What is the salary of a software testing student?
力扣:70. 爬楼梯
The difference between px, em, and rem