首页 \ 问答 \ 添加来自此值之前的向量的第二个值(Adding the second values from a vector which appear before this value)

添加来自此值之前的向量的第二个值(Adding the second values from a vector which appear before this value)

所以,我试图创建一个通过对向量移位的函数,并将先前值的第二个值添加到当前目标。 但是,我不确定如何向后循环以获取之前在目标之前的所有值。

以下是我迄今为止所做的:

int cWeight (KEY_T key) const
{
    int size = _valueToWeightMap.size();

    for (int x = 0; x < size; x++)
    {
        if (_valueToWeightMap[x].first == key && x == 0)
            return _valueToWeightMap[x].second;

        if (_valueToWeightMap[x].first == key && x != 0)
            return _valueToWeightMap[x].second + _valueToWeightMap[x - 1].second;
    }

    return 0;
}

_valueToWeightMap是向量的名称,而KEY_T只是查找字符串的类型名称。

目前,该函数只捕获矢量中右对齐的二次值,但我希望它从它后面的所有对象中获取二次值。 我该怎么做呢?

这是我添加到矢量中的一些东西。

dist1.add("Helmet", 1);
dist1.add("Boots", 10);
dist1.add("Gloves", 20);
dist1.add("Cloud", 15);
dist1.add("Ring", 4);
dist1.add("Wind", 12);

所以,我想要的功能是这样的:

  1. 位置0中的对的第二个值等于1,因此该函数应返回一个。
  2. 位置1中的对的第二个值等于10,因此函数应返回11.(10 + 1)
  3. 位置2中的对具有等于20的第二个值,所以它应该返回31.(20 + 10 + 1)等等。

So, I'm attempting to make a function that shifts through a vector of pairs and adds the second value of to the previous values to the current target. However, I'm unsure of how to loop backwards to grab all of the values that were previously before the target.

Here's what I have done so far:

int cWeight (KEY_T key) const
{
    int size = _valueToWeightMap.size();

    for (int x = 0; x < size; x++)
    {
        if (_valueToWeightMap[x].first == key && x == 0)
            return _valueToWeightMap[x].second;

        if (_valueToWeightMap[x].first == key && x != 0)
            return _valueToWeightMap[x].second + _valueToWeightMap[x - 1].second;
    }

    return 0;
}

The _valueToWeightMap is the name of the vector, and KEY_T is just a typename that looks for strings.

Currently, the function only grabs the secondary value from the pair right behind it in the vector, however I want it to grab the secondary value from all the ones behind it. How would I go about doing this?

Here's some things I added to the vector.

dist1.add("Helmet", 1);
dist1.add("Boots", 10);
dist1.add("Gloves", 20);
dist1.add("Cloud", 15);
dist1.add("Ring", 4);
dist1.add("Wind", 12);

So, what I want the function to do is this:

  1. The pair in position 0 has its second value equal to 1, so the function should return one.
  2. The pair in the position 1 has its second value equal to 10, so the function should return 11. (10 + 1)
  3. The pair in position 2 has its second value equal to 20, so it should return 31. (20 + 10 + 1) and so on.

原文:https://stackoverflow.com/questions/46946404
更新时间:2022-01-16 12:01

最满意答案

ng lint打印到标准输出以便执行:

ng lint > out.txt

适用于* nix和Windows


ng lint prints to stdout so execute:

ng lint > out.txt

Works on both *nix and Windows

相关问答

更多
  • 转到行为选项卡,取消选中“干净”,在那里添加你的皮棉选项(为我解决了这个问题) 去: 菜单栏:窗口| 优先 导航树:C / C ++ | 建立 选择选项卡:“Error Parsers” 点击解析器列表右侧的“添加”,并将其命名为“我的Funky PCLint RegEX”并将其选中 在下面的“错误解析器选项”框中点击“添加” 例如一个不完美的列表 严重性:信息 模式:(。 )([0-9] ):错误 - >信息(。*) 文件:$ 1 线路:$ 2 描述:$ 3 和 - 严重性:警告 - 模式:(。 )([0 ...
  • 我发现了这个问题: codelyzer已经过时了。 我将它从0.0.26更新到2.1.1 ,现在tslint成功地使用了我们的代码。 npm update codelyzer --save-dev I found the issue: codelyzer was out of date. I updated it from 0.0.26 to 2.1.1 and now tslint is successfully linting our code. npm update codelyzer --save- ...
  • 您可以通过以下方式在Gradle中提供XML报告输出文件: lintOptions { xmlOutput file("lint-results.xml") } xmlOutput方法需要文件类型参数。 我在参数中使用了相对路径。 您也可以将它与projectDir一起使用。 lintOptions { xmlOutput file("$projectDir/lint-results.xml") } Here's how I solved it. stage('Lint run') { ...
  • 对于遇到同样问题的任何人,我通过在项目的gradle文件中添加maven { url 'https://maven.google.com' } url'https://maven.google.com maven { url 'https://maven.google.com' }来解决它 allprojects { repositories { mavenLocal() jcenter() maven { url 'https://maven.goo ...
  • 我无法使用从toTree传入的树,所以我决定从toTree应用程序中抓取样式树,这似乎已经完成了。 我觉得这更像是西兰花 - scsslint比ember-cli的限制。 如果有人可以建议改进,你可以在这里查看我的代码: ember-cli-scsslint I was unable to use the tree passed in from toTree so I instead settled for grabbing the styles tree from the application app. ...
  • ng lint打印到标准输出以便执行: ng lint > out.txt 适用于* nix和Windows ng lint prints to stdout so execute: ng lint > out.txt Works on both *nix and Windows
  • 目前这是不可能的。 一旦Android插件与Java插件兼容,您就可以运行其他提供Gradle插件的静态分析工具(findbugs,pmd等...)。 不过,这将在他们自己的报告中。 This is not possible at the moment. Once the Android plugin is compatible with the Java plugin you'll be able to run other static analysis tools that provides a Gra ...
  • 今天的工具无法做到这一点。 你可以做的是在你最喜欢的编辑器中获得一个tslint扩展。 这将在编辑器中显示错误。 对于VS Code,只需搜索tslint即可直接显示扩展名。 您还可以将其作为NPM脚本的一部分。 例如,在package.json : "scripts": { "build": "ng lint && ng build" } 这仍然不是交互式的,但您可以在推送代码之前开发人员需要运行它的一个版本,并且您的CI构建工具也可以运行。 对于交互式体验,代码编辑器扩展程序尽可能接近。 在VS ...
  • 这确实是android lint声纳插件1.1中的一个错误,请参阅与此问题相关的故障单: https : //jira.sonarsource.com/browse/SONARANDRO-38 这应该在声纳android lint插件的1.2版本中修复。 This is indeed a bug in android lint sonar plugin 1.1, see the ticket associated with this issue : https://jira.sonarsource.com/ ...
  • 从命令行运行gradlew lintDebug (或gradlew lint[variantName]以获取其他变体)。 这将在/ app / build / outputs中生成完整的lint报告。 我推荐HTML版本(lint-results-debug.html)。 在那里,您将找到所有Android lint问题及其严重性。 或者,您可以转到Android Studio中的分析>检查代码以运行lint。 切换视图按严重程度对它们进行分组 - 错误是阻止构建的错误。 From the command ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)