【问题标题】:Add the value of each column in the sliced values在切片值中添加每列的值
【发布时间】:2021-12-21 01:21:55
【问题描述】:

我想在切片值中添加每列的值。我想得到每列的总和。你能帮帮我吗?

int main(void)
{
    char serial[] = "XQXQT6FM6YNN26PNRM1S7QRESA0W01TV";
    
    //get length of serial 
    int len_key = strlen(serial);
    BYTE arr[len_key];
    int i;

    //converting string to BYTE[]
    SerialtoByte(serial, arr);
    
    for(i=0; i<len_key; i++)
    {
        cout<<" "<<arr[i];
    }
    
    cout<<"\n\n";
    sliceKey(arr);
    cout<<"\n\n";
}

字节值

88 81 88 81 84 54 70 77 54 89 78 78 50 54 80 78 82 77 49 83 55 81 82 69 83 65 48 87 48 49 84 86

这是切片值

88 81 88 81 84 54 70 77 
54 89 78 78 50 54 80 78 
82 77 49 83 55 81 82 69 
83 65 48 87 48 49 84 86 

【问题讨论】:

  • 你想做某事,你有代码。问题是什么?您具体需要什么帮助?
  • 请澄清您的具体问题或提供更多详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: c++ arrays string byte slice


【解决方案1】:

嗯,这是一种方法,使用模运算符:

int sumOfColumnValue[8] = {0};
for(i=0; i < len_key; i++)
{
    sumOfColumnValue[i % 8] += arr[i];
}
// print the first column's sum:
std::cout << sumOfColumnValue[0];

【讨论】:

  • @LemuelFajarda 我已经编辑了我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-31
  • 2016-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
相关资源
最近更新 更多