当前位置:网站首页>OJ 1242 freshman's debut
OJ 1242 freshman's debut
2022-07-28 06:38:00 【JETECHO】
describe
Four years ago today , You are thinking about where and what kind of university I should go , You think you can learn …, The result is very lucky to come to Zhejiang University of traditional Chinese Medicine , Ah , Now that it's here , That's not bullshit , At this time, you should be able to help me calculate A+B. Here you are, you two , You add the odd digits of the first number and the even digits of the second number to get a number , Then add the even digits of the first number and the odd digits of the second number to get a number , Then output the sum of these two newly obtained numbers .
Input
Enter two numbers A,B《 The scope does not exceed long long 》
Output
Output the above and
sample input 1
123
456
sample output 1
21
The title says odd and even digits , It is relatively troublesome to directly use integers , Sure Use string , Traversal string , Through this traversal, you only need to cycle to find odd and even digits .
#include <iostream>
using namespace std;
int main()
{
string a,b;
while(cin>>a>>b)
{
long long sum1=0,sum2=0;
for(int i=0; i<a.size(); i++)
{
if(i%2==0)
sum1=sum1+a[i]-'0';
else
sum2=sum2+a[i]-'0';
}
for(int i=0; i<b.size(); i++)
{
if(i%2!=0)
sum1=sum1+b[i]-'0';
else
sum2=sum2+b[i]-'0';
}
cout<<sum1+sum2<<endl;
}
return 0;
}
边栏推荐
- 刷题记录----哈希表
- 自定义组件--样式
- 2022-07-17 Damon database installation
- [PTA--利用队列解决猴子选大王问题】
- 战疫杯--奇奇怪怪的形状
- In vscade, the source file "adafruit_gfx.h" cannot be opened“
- ubunut 服务器上传下载文件
- Development of clip arbitrage / brick carrying arbitrage system
- Treasure plan TPC system development DAPP construction
- 七夕送女朋友什么礼物好?不会送礼的男生速看!
猜你喜欢
随机推荐
小程序创建组件
OJ 1089 春运
微信小程序自定义编译模式
STM32的IAP跳转相关bug经历
关于时间复杂度,你不知道的都在这里
2022-07-19 达梦数据库 连接实例、执行脚本、系统命令
【学习笔记】工具
In vscade, the source file "adafruit_gfx.h" cannot be opened“
开放式耳机推荐哪款最好、性价比最高的开放式耳机
MySQL安装与使用
动态规划--简单题型之爬楼梯
战疫杯--奇奇怪怪的形状
刷题记录----链表
2022-07-19 Damon database connection instance, execution script, system command
NFT data storage blind box + mode system development
Redhawk Dynamic Analysis
set_ multicycle_ path
[c语言]--一步一步实现扫雷小游戏
【二叉树基础知识】
2022年七夕礼物推荐!好看便宜又实用的礼物推荐









