当前位置:网站首页>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.1 Arrays are not pointers
- 嵌入式系统驱动初级【4】——字符设备驱动基础下_并发控制
- BFC、IFC、GFC、FFC概念理解、布局规则、形成方法、用处浅析
- warning C4251: “std::vector<_Ty>”需要有 dll 接口由 class“Test”的客户端使用错误
- Use Patroni callback script to bind VIP pit
- 去重的几种方式
- 8大软件供应链攻击事件概述
- The string class introduction
- static在不同位置定义变量居然还有不同的含义?
- Cannot read properties of null (reading ‘insertBefore‘)
猜你喜欢
![[One step in place] Jenkins installation, deployment, startup (complete tutorial)](/img/f2/15fb546eb864d7ff40b5507d5c7aa5.png)
[One step in place] Jenkins installation, deployment, startup (complete tutorial)

想好了吗?

Teenage Achievement Hackers Need These Skills

Dynamic programming of the division of numbers

解决错误:npm WARN config global `--global`, `--local` are deprecated

OpenSSF 安全计划:SBOM 将驱动软件供应链安全

el-Select selector bottom fixed

C语言 -- 操作符详解

DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片

谷粒商城-基础篇(项目简介&项目搭建)
随机推荐
C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking
MySql data recovery method personal summary
高性能高可靠性高扩展性分布式防火墙架构
去重的几种方式
LCP 17. 速算机器人
Redis common interview questions
Get the selected content of the radio box
npm init [email protected] 构建项目报错SyntaxError: Unexpected token ‘.‘解决办法
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
【JS】js给对象动态添加、设置、删除属性名和属性值
CentOS7 - yum install mysql
离线采集怎么看sql执行计划
MySQL日期函数
npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
8. Custom mapping resultMap
7、特殊SQL的执行
What is the salary of a software testing student?
5个开源组件管理小技巧
Grain Mall - Basics (Project Introduction & Project Construction)
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers