当前位置:网站首页>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;}
边栏推荐
- 7.13 Day20----MYSQL
- warning C4251: “std::vector<_Ty>”需要有 dll 接口由 class“Test”的客户端使用错误
- OpenRefine中的正则表达式
- The difference between px, em, and rem
- What are the steps for how to develop a mall system APP?
- sql server如何得到本条记录与上一条记录的差异,即变动值
- 你以为border-radius只是圆角吗?【各种角度】
- JS基础--强制类型转换(易错点,自用)
- 【评价类模型】Topsis法(优劣解距离法)
- OpenCV获取和设置图像的平均亮度
猜你喜欢
npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
7.18 Day23 - the markup language
About yolo7 and gpu
Teenage Achievement Hackers Need These Skills
败给“MySQL”的第60天,我重振旗鼓,四面拿下蚂蚁金服offer
Web Basics and Exercises for C1 Certification - My Study Notes
The difference between px, em, and rem
8.03 Day34---BaseMapper query statement usage
嵌入式系统驱动初级【3】——字符设备驱动基础中_IO模型
Get the selected content of the radio box
随机推荐
el-Select selector bottom fixed
C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
动态规划总括
Uni-app 小程序 App 的广告变现之路:全屏视频广告
DataTable uses Linq for grouping and summarization, and converts the Linq result set into DataTable
Dynamic programming of the division of numbers
JS基础--强制类型转换(易错点,自用)
Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions
canal实现mysql数据同步
注意!软件供应链安全挑战持续升级
8大软件供应链攻击事件概述
入坑软件测试的经验与建议
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
应届生软件测试薪资大概多少?
梳理CamStyle、PTGAN、SPGAN、StarGAN
CentOS7 - yum install mysql
你以为border-radius只是圆角吗?【各种角度】
Resolved error: npm WARN config global `--global`, `--local` are deprecated
力扣:63. 不同路径 II
The Road to Ad Monetization for Uni-app Mini Program Apps: Full Screen Video Ads