当前位置:网站首页>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;} 边栏推荐
- The string class introduction
- Chapter 5 C programming expert thinking 5.4 alert Interpositioning of links
- canal实现mysql数据同步
- 4.1 JdbcTemplate for declarative transactions
- Resolved error: npm WARN config global `--global`, `--local` are deprecated
- Dynamic programming of the division of numbers
- Shocked, 99.9% of the students didn't really understand the immutability of strings
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.3 What is a Declaration and What is a Definition
- 7.13 Day20----MYSQL
- 力扣:96.不同的二叉搜索树
猜你喜欢

Summary of MySQL database interview questions (2022 latest version)

【论文阅读笔记】无监督行人重识别中的采样策略

7.18 Day23 - the markup language

符号表

【一步到位】Jenkins的安装、部署、启动(完整教程)
![[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection](/img/1a/b3bdf9b62c82b0fc4d913045981d94.png)
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection

想好了吗?

The idea setting recognizes the .sql file type and other file types

(Kettle) pdi-ce-8.2 连接MySQL8.x数据库时驱动问题之终极探讨及解决方法分析
![Embedded system driver primary [3] - _IO model in character device driver foundation](/img/c7/21fc0651964a6a435e8ec5743b7662.png)
Embedded system driver primary [3] - _IO model in character device driver foundation
随机推荐
Gartner 权威预测未来4年网络安全的8大发展趋势
9. Dynamic SQL
力扣:509. 斐波那契数
What are the steps for how to develop a mall system APP?
[Cocos 3.5.2]开启模型合批
npm init [email protected] 构建项目报错SyntaxError: Unexpected token ‘.‘解决办法
离线采集怎么看sql执行计划
DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
代码重构:面向单元测试
Programming hodgepodge (4)
如何低成本修bug?测试左移给你答案
npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
OpenSSF 安全计划:SBOM 将驱动软件供应链安全
Do you think border-radius is just rounded corners?【Various angles】
4.1 JdbcTemplate for declarative transactions
7.13 Day20----MYSQL
你以为border-radius只是圆角吗?【各种角度】
DataTable uses Linq for grouping and summarization, and converts the Linq result set into DataTable
自动化测试的成本高效果差,那么自动化测试的意义在哪呢?
字节最爱问的智力题,你会几道?