如何乘以cstring的偶数位元素(局部算法) [英] How to multiply the even digit position elements of a cstring(local algorithm)

查看:59
本文介绍了如何乘以cstring的偶数位元素(局部算法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Cstring1234567890必须乘以偶数位置的所有数字,即第2,第4,第6 ......与1,2,3,1,2,3 ...

Ex :(第2个pos元素*第1,4个pos元素* 2,6thpos元素* 3,8个pos元素* 1,10个pos元素* 2 .......)



我尝试了什么:



i试图根据位置将CString拆分为2个阵列并尝试相乘偶数位置1,2,3 ....

i have a Cstring "1234567890" have to multiply all digits in even position i.e,2nd,4th,6th.... with 1,2,3,1,2,3...
Ex:(2nd pos element*1,4th pos element*2,6thpos element*3,8th pos element*1,10th pos element*2 .......)

What I have tried:

i have tried to split CString into 2 arrays based on position and tried to multiply the even digit positions with 1,2,3....

推荐答案

不知道为什么你需要拆分字符串......



如果那么记法,请考虑这个,'i'是从0到某个数字的整数



Dont know why you need to split the string as such ..

think about this in shorthand if then notation, 'i' is an integer from 0 to some number

((i % 2)  == 0 ? "Even" : "Odd"





什么是'%'? - 它的'Mod'即模数oper ator - 查阅



假设你有'i',从0到某个数字的整数,你怎么从它获得1,2,3?再次,想'%'





What is '%' ? - its the 'Mod' ie Modulus operator - look it up

Assuming you have 'i' as above, an integer from 0 to some number, how do you get 1,2,3 from it ? again, think '%'

(i % 3) + 1





如果不加拼写,那应该给你足够的弹药来解决你的问题



Without spelling it out even more, that should give you enough ammunition to approach your problem


这篇关于如何乘以cstring的偶数位元素(局部算法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆