为什么在Codechef中提交此代码时出现运行时错误(SIGABRT)?

萨沙姆

当我在系统上运行该代码时,该代码成功执行,但是当我在codechef上提交代码时,它会遇到运行时错误(Runtime Error(SIGABRT))。

这是问题的链接http://www.codechef.com/problems/LELUCKYN

这是什么错误,我该如何解决?

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int main() {
    int t;
    cin >> t;
    for ( auto i = 1; i <= t; i++ ) {
        int n;
        cin >> n;
        vector<int> vec(n);
        for ( auto in = 0; in < n; in++ ) {
            int input;
            cin >> input;
            vec[in] = input;
        }
        int count = 0;
        for (int x = 0; x < vec.size(); x++ ) {
            for ( int y = x; y < vec.size(); y++ ) {
                string num="";
                for (int z = x; z <= y; z++ ) {
                    num.append(to_string(vec[z]));
                }
                int number = stoi(num);
                int c4 = 0, c7 = 0;
                while ( number != 0 ) {
                    int d = number % 10;
                    if ( d == 4) c4++;
                    else if (d ==7 ) c7++;
                    number/= 10;
                }
                int po = (int)pow( c4, c7 );
                if (c4 != 2 && c7 != 2 && po <= ( ( y - x ) + 1 )) count++;
            }
        }
        cout << count << endl;
    }
}
莫尔布德尼洛

如果我正确地阅读了您的代码,则是将所有数字连接到一个字符串中,然后尝试将其转换为一个int数字以便对数字进行计数。

该字符串将不会始终转换为该字符串,int因为它太大了,stoi在这种情况下会引发异常。

你可以只算得到的字符串中的数字(数'4'S和'7's,而不是4S和7S),或者你可以在每个数算数字,并把它们加起来,不通过字符串转换去。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么此代码给运行时分段错误?

来自分类Dev

为什么在运行“ bower install”时出现此错误?

来自分类Dev

C中的运行时错误(CodeChef)

来自分类Dev

为什么ClassCastException是运行时错误?

来自分类Dev

为什么在运行文件时出现此错误?

来自分类Dev

运行Go代码时出现运行时错误

来自分类Dev

为什么每次尝试在用户界面中运行代码时都会出现此错误?

来自分类Dev

为什么会出现运行时错误?

来自分类Dev

为什么此异常不会导致运行时错误?

来自分类Dev

使用python在uva中提交代码时出现运行时错误

来自分类Dev

为什么此代码编译并在执行时给出运行时错误

来自分类Dev

为什么我的代码运行时始终出现“对象'Range'失败”错误,但我将此代码附加到按钮时却没有出现?

来自分类Dev

为什么在struct中使用字符串时出现运行时错误

来自分类Dev

为什么在运行optaplanner .jar时出现此错误?

来自分类Dev

为什么此C代码在调试时能正常运行,但在正常运行时却不能正常运行?

来自分类Dev

为什么运行此功能时出现类型错误?

来自分类Dev

为什么会出现访问冲突运行时错误?

来自分类Dev

为什么我的代码出现运行时错误?

来自分类Dev

为什么在读取文件时出现运行时错误

来自分类Dev

CodeChef-运行时错误(SIGSEGV)

来自分类Dev

为什么我的代码给出运行时错误?

来自分类Dev

运行时错误(NZEC)-Python / Codechef

来自分类Dev

为什么每当我将API密钥放入build.gradle时都会出现运行时错误?

来自分类Dev

使用python在uva中提交代码时出现运行时错误

来自分类Dev

为什么在联机提交此代码时出现运行时错误?(jdk 1.7)

来自分类Dev

为什么在运行简单的docker映像时出现oci运行时错误?

来自分类Dev

VBA - 运行此代码时出现运行时错误“1004”

来自分类Dev

为什么我的 prgram 在 codechef ide 中显示运行时错误,而它不在 Visual Studio 中?

来自分类Dev

为什么此代码在 URI Online Judge 中给出“运行时错误”

Related 相关文章

  1. 1

    为什么此代码给运行时分段错误?

  2. 2

    为什么在运行“ bower install”时出现此错误?

  3. 3

    C中的运行时错误(CodeChef)

  4. 4

    为什么ClassCastException是运行时错误?

  5. 5

    为什么在运行文件时出现此错误?

  6. 6

    运行Go代码时出现运行时错误

  7. 7

    为什么每次尝试在用户界面中运行代码时都会出现此错误?

  8. 8

    为什么会出现运行时错误?

  9. 9

    为什么此异常不会导致运行时错误?

  10. 10

    使用python在uva中提交代码时出现运行时错误

  11. 11

    为什么此代码编译并在执行时给出运行时错误

  12. 12

    为什么我的代码运行时始终出现“对象'Range'失败”错误,但我将此代码附加到按钮时却没有出现?

  13. 13

    为什么在struct中使用字符串时出现运行时错误

  14. 14

    为什么在运行optaplanner .jar时出现此错误?

  15. 15

    为什么此C代码在调试时能正常运行,但在正常运行时却不能正常运行?

  16. 16

    为什么运行此功能时出现类型错误?

  17. 17

    为什么会出现访问冲突运行时错误?

  18. 18

    为什么我的代码出现运行时错误?

  19. 19

    为什么在读取文件时出现运行时错误

  20. 20

    CodeChef-运行时错误(SIGSEGV)

  21. 21

    为什么我的代码给出运行时错误?

  22. 22

    运行时错误(NZEC)-Python / Codechef

  23. 23

    为什么每当我将API密钥放入build.gradle时都会出现运行时错误?

  24. 24

    使用python在uva中提交代码时出现运行时错误

  25. 25

    为什么在联机提交此代码时出现运行时错误?(jdk 1.7)

  26. 26

    为什么在运行简单的docker映像时出现oci运行时错误?

  27. 27

    VBA - 运行此代码时出现运行时错误“1004”

  28. 28

    为什么我的 prgram 在 codechef ide 中显示运行时错误,而它不在 Visual Studio 中?

  29. 29

    为什么此代码在 URI Online Judge 中给出“运行时错误”

热门标签

归档