当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

qt自定义滑动按钮(美观且使用方便)

1、 Ffmpeg record audio as PCM file

MySQL安装与使用

NFT data storage blind box + mode system development

Problems of font modification and line spacing in word automatic directory

2022-06-07 ResponseBodyAdvice导致Swagger出现弹框问题
![[PTA----输出全排列]](/img/66/d1699cd55fa5ff4a55e3e150d02c1b.png)
[PTA----输出全排列]

C语言memcpy库函数与memmove的作用

战疫杯--奇奇怪怪的形状

气传导耳机哪个品牌比较好、这四款不要错过
随机推荐
气传导耳机哪个品牌比较好、这四款不要错过
My notes
[哈希表基础知识]
开放式耳机有哪些、四款音质超好的气传导耳机推荐
OJ 1507 删数问题
微信小程序自定义编译模式
Getting started with hugging face
藏宝计划TPC系统开发Dapp搭建
2022-05-15 based on JWT token
【动态规划--买卖股票的最佳时期系列】
气导贴耳式耳机推荐、不需要佩戴入耳的气传导耳机
我的部署笔记
2022-07-17 Damon database installation
Several methods of QT setting loading interface
[c语言]简易通讯录的实现
MFC uses the console to print program information
Problems of font modification and line spacing in word automatic directory
七夕送什么礼物好?小众又高级的产品礼物推荐
What are the open earphones? Four types of air conduction earphones with excellent sound quality are recommended
Icc2 (IV) routing and postroute optimization