当前位置:网站首页>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;}
边栏推荐
猜你喜欢
What is the salary of a software testing student?
Summary of MySQL database interview questions (2022 latest version)
About yolo7 and gpu
8、自定义映射resultMap
Cannot read properties of null (reading ‘insertBefore‘)
Towards Real-Time Multi-Object Tracking (JDE)
Shocked, 99.9% of the students didn't really understand the immutability of strings
7.18 Day23 - the markup language
Delphi-C端有趣的菜单操作界面设计
解决错误:npm WARN config global `--global`, `--local` are deprecated
随机推荐
npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
Do you think border-radius is just rounded corners?【Various angles】
Web Basics and Exercises for C1 Certification - My Study Notes
【评价类模型】Topsis法(优劣解距离法)
idea设置识别.sql文件类型以及其他文件类型
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
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.4 Matching declarations to definitions
TensorRTx-YOLOv5工程解读(一)
DataTable uses Linq for grouping and summarization, and converts the Linq result set into DataTable
MySql data recovery method personal summary
[Cocos] cc.sys.browserType可能的属性
[SemiDrive source code analysis] [MailBox inter-core communication] 47 - Analysis of RPMSG_IPCC_RPC mode limit size of single transmission and limit bandwidth test
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
【JS】js给对象动态添加、设置、删除属性名和属性值
DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
Tactile intelligent sharing - SSD20X realizes upgrade display progress bar
嵌入式系统驱动初级【4】——字符设备驱动基础下_并发控制
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
解决错误:npm WARN config global `--global`, `--local` are deprecated
Landing, the IFC, GFC, FFC concept, layout rules, forming method, use is analysed