当前位置:网站首页>LCP 17. 速算机器人
LCP 17. 速算机器人
2022-08-04 05:18:00 【Mr Gao】
LCP 17. 速算机器人
小扣在秋日市集发现了一款速算机器人。店家对机器人说出两个数字(记作 x 和 y),请小扣说出计算指令:
"A" 运算:使 x = 2 * x + y;
"B" 运算:使 y = 2 * y + x。
在本次游戏中,店家说出的数字为 x = 1 和 y = 0,小扣说出的计算指令记作仅由大写字母 A、B 组成的字符串 s,字符串中字符的顺序表示计算顺序,请返回最终 x 与 y 的和为多少。
示例 1:
输入:s = "AB"
输出:4
解释:
经过一次 A 运算后,x = 2, y = 0。
再经过一次 B 运算,x = 2, y = 2。
最终 x 与 y 之和为 4。
这题其实就很简单了,解题代码如下:
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'){
x=fA(x,y);
}
else{
y=fB(x,y);
}
}
return x+y;
}
边栏推荐
- 渗透测试(PenTest)基础指南
- 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 language advanced] program environment and preprocessing
- C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.3 什么是声明,什么是定义
- As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
- What is the salary of a software testing student?
- centos 安装postgresql13 指定版本
- 附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;
- 深度学习21天——准备(环境配置)
- Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用
猜你喜欢

【C语言进阶】程序环境和预处理

【云原生--Kubernetes】Pod资源管理与探针检测

leetcode 12. 整数转罗马数字

7-3 LVS+Keepalived Cluster Description and Deployment

Do you think border-radius is just rounded corners?【Various angles】

OpenSSF 安全计划:SBOM 将驱动软件供应链安全
![[Cocos 3.5.2]开启模型合批](/img/d9/9e8f71c9a26c8052b11291fe3ba7ac.png)
[Cocos 3.5.2]开启模型合批

Get the selected content of the radio box

【流程图】

System design. Seckill system
随机推荐
[Cocos 3.5.2]开启模型合批
Will the 2023 PMP exam use the new version of the textbook?Reply is here!
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.3 什么是声明,什么是定义
有趣的 Kotlin 0x0E:DeepRecursiveFunction
如何将 DevSecOps 引入企业?
QT 如何识别文件的编码格式
【一步到位】Jenkins的安装、部署、启动(完整教程)
注意!软件供应链安全挑战持续升级
力扣:63. 不同路径 II
数的划分之动态规划
你以为border-radius只是圆角吗?【各种角度】
文献管理工具 | Zotero
[21 Days Learning Challenge] Image rotation problem (two-dimensional array)
C专家编程 第5章 对链接的思考 5.6 轻松一下---看看谁在说话:挑战Turning测验
C专家编程 第5章 对链接的思考 5.4 警惕Interpositioning
Resolved error: npm WARN config global `--global`, `--local` are deprecated
[Skill] Using Sentinel to achieve priority processing of requests
What are the steps for how to develop a mall system APP?
Performance testing with Loadrunner
[Cocos] cc.sys.browserType可能的属性