【问题标题】:Codechef Enormous Input Test SolutionCodechef 海量输入测试解决方案
【发布时间】:2015-11-12 06:28:02
【问题描述】:

我正在 codechef https://www.codechef.com/problems/INTEST 上解决这个问题

我正在使用以下代码,它在我的系统上给出了正确的答案,但在我提交时给出了错误的答案。这是为什么呢?

#include <stdio.h>

int main(void) 
{
    unsigned int n, k, ti, dv;
    scanf("%d %d", &n, &k);
    int i = 0;
    while (i < n)
    {
        scanf("%d", &ti);
        if ((ti % k) == 0)
            dv++;
        i++;
    }
    printf("%d", dv);

    return 0;
}

我用问题页面上给出的输入试了一下,得到了正确答案

【问题讨论】:

  • 您正在使用“%d”而不是“%u”作为无符号整数...这可能是问题所在...
  • 和 dv 未初始化使用
  • dv 未初始化。那就是问题所在。谢谢
  • 有什么办法可以优化吗?
  • 当您遇到此类问题时“我的系统上正确答案,但我提交时答案错误” 使用Codechef ide 查找问题:)

标签: c algorithm


【解决方案1】:

这是我的 Python3 解决方案:

try:
  n,k=map(int,input().split())
  count=0
  for i in range(n):
    x=int(input())
    if x%k==0:
      count+=1
  print(count)
except:
  pass

【讨论】:

    【解决方案2】:

    Python3解决方案-

    n,k = list(map(int,input().split()))
    count = 0
    for _ in range(n):
        if (int(input()) % 3 == 0):
        count+=1
    print(count)
    

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2011-04-03
      相关资源
      最近更新 更多