当前位置:网站首页>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;
}
边栏推荐
- 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
- 编程大杂烩(四)
- 渗透测试(PenTest)基础指南
- How to keep the source code confidential in the development under the burning scenario
- C Expert Programming Chapter 5 Thinking about Linking 5.1 Libraries, Linking and Loading
- ADC噪声全面分析 -03- 利用噪声分析进行实际设计
- TSF微服务治理实战系列(一)——治理蓝图
- 擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
- 基于gRPC编写golang简单C2远控
- 附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;
猜你喜欢

结构体指针知识要点总结

Converts XML tags to TXT format (voc conversion for yolo convenient training)

day13--postman接口测试

Turn: Management is the love of possibility, and managers must have the courage to break into the unknown

3000字,一文带你搞懂机器学习!

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

编程大杂烩(四)

你以为border-radius只是圆角吗?【各种角度】

符号表

ADC噪声全面分析 -03- 利用噪声分析进行实际设计
随机推荐
ADC噪声全面分析 -03- 利用噪声分析进行实际设计
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.1 数组并非指针
C Expert Programming Chapter 5 Thinking about Linking 5.1 Libraries, Linking and Loading
idea设置识别.sql文件类型以及其他文件类型
el-Select selector bottom fixed
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
What is the salary of a software testing student?
21 days learning challenge 】 【 sequential search
解决错误:npm WARN config global `--global`, `--local` are deprecated
C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking
败给“MySQL”的第60天,我重振旗鼓,四面拿下蚂蚁金服offer
el-Select 选择器 底部固定
获取单选框选中内容
商城App开发都有哪些功能呢
《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事
About yolo7 and gpu
路网编辑器技术预研
应届生软件测试薪资大概多少?
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
Uni-app 小程序 App 的广告变现之路:全屏视频广告