当前位置:网站首页>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;
}
边栏推荐
- Large chain best freight d audit with what software?What are the functions?
- 字节最爱问的智力题,你会几道?
- C专家编程 第5章 对链接的思考 5.2 动态链接的优点
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
- The symbol table
- flink cdc一启动,源端Oracle那台服务器的CPU就飙升到80%以上,会是啥原因呢?
- 7-2 LVS+DR Overview and Deployment
- 【流程图】
- 附加:对于“与数据表对应的实体类“,【面对MongoDB时,使用的@Id等注解】和【以前面对MySQL时,使用的@Id等注解】,是不同的;
- 结构体函数练习
猜你喜欢

【评价类模型】Topsis法(优劣解距离法)

What is the salary of a software testing student?

7-2 LVS+DR Overview and Deployment

获取单选框选中内容

3面头条,花7天整理了面试题和学习笔记,已正式入职半个月

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

详解八大排序

See how DevExpress enriches chart styles and how it empowers fund companies to innovate their business

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

深度学习21天——准备(环境配置)
随机推荐
【JS】js给对象动态添加、设置、删除属性名和属性值
share总结
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
Programming hodgepodge (4)
7-3 LVS+Keepalived Cluster Description and Deployment
编程大杂烩(四)
力扣:63. 不同路径 II
解决错误:npm WARN config global `--global`, `--local` are deprecated
el-Select selector bottom fixed
8大软件供应链攻击事件概述
For Qixi Festival, I made a confession envelope with code
day13--postman接口测试
路网编辑器技术预研
C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking
Converts XML tags to TXT format (voc conversion for yolo convenient training)
What is the salary of a software testing student?
OpenGL绘制圆
2022 software test interview questions The latest ByteDance 50 real interview questions, 15k have been won after brushing, with explanation + Q&A
Shocked, 99.9% of the students didn't really understand the immutability of strings
QT 如何识别文件的编码格式