- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题来自spoj。请参阅this供提问。正如您所看到的,我的逻辑很简单。如果我将动态形式的数组大小更改为静态数组大小,则代码将执行并请求整数,并无限期地继续执行,同时它应该运行测试用例的数量。但是,如果我保持动态,我就会不断收到此持续错误:file_name.exe 已停止工作。
也请对我的代码发表评论。
#include <stdio.h>
#include <conio.h>
int main()
{
int n, i, count, k, tcs, j, l, m;
scanf("%d", tcs);
int fact[tcs];
int arr[tcs];
for (j = 0; j < tcs; j++) {
scanf("%d", &arr[j]);
}
int calc_fact(n) {
if (n == 1)
return 1;
else
return n * calc_fact(n - 1);
}
j = 0;
m = 0;
while (m < tcs && j < tcs) {
fact[m] = calc_fact(arr[j]);
m++;
j++;
}
m = 0;
for (l = 0; l < tcs; l++) {
i = 1;
count = 0;
while (i <= fact[m]) {
if ((fact[m]) % i == 0)
count++;
i++;
}
m++;
k = (count) % ((10 ^ 9) + 7);
printf("\n%d", k);
}
return 0;
}
最佳答案
假设您使用的是 C++,则需要在代码中更改一些内容:
scanf("%d", tcs);
应该是 scanf("%d", &tcs);
这个错误是你的程序崩溃的原因,因为tcs
没有正确的预期值。int calc_fact(n)
应位于原型(prototype)为 int calc_fact(int n)
的 main() 函数之外。由于这个错误,您的代码首先将无法编译(当您说静态声明数组时您的代码符合要求时,您确定吗?请参阅下面修改后的代码:
#include <stdio.h>
//#include <conio.h> //You actually don't need it.
int calc_fact(int n)
{
if(n==1)
return 1;
else
return n*calc_fact(n-1);
}
int main()
{
int n, i, count, k, tcs, j, l, m;
scanf("%d", &tcs);
int fact[tcs];
int arr[tcs];
for(j=0; j<tcs; j++)
{
scanf("%d", &arr[j]);
}
j=0;
m=0;
while(m<tcs && j<tcs)
{
fact[m]=calc_fact(arr[j]);
m++;
j++;
}
m=0;
for(l=0; l<tcs; l++)
{
i=1;
count=0;
while(i<=fact[m])
{
if((fact[m])%i==0)
count++;
i++;
}
m++;
k=(count)%((10^9)+7);
printf("%d\n", k); //and not printf("\n%d", k);
}
return 0;
}
工作代码here .
关于c - "file_name.exe has stopped working",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693297/
这个问题在这里已经有了答案: Bash check shows file exists for non-existent files? (3 个答案) 关闭 4 年前。 我知道 [ -f file
我有一个文件 HDFS中的/user/nts/.\file_name 我想将此文件重命名为 / user / nts / file_name hdfs dfs -ls将列出此文件 我尝试了几种在SO中
脚本与 ./file_name 一起工作,但是当我使用 sh file_name 启动它时出现错误 #!/bin/bash echo "Scenarijus, kuris is teksto fail
我有两段代码,它们都是为了做同样的事情——坐在一个循环中,直到一个文件被写入完成。它们都主要用于通过 FTP/SCP 传入的文件。 代码的一个版本使用os.stat()[stat.ST_SIZE]:
在删除文件的地方进行 merge 后,“git log -- file_name”没有显示当前分支的提交。但是,如果我执行“git log”或“git log --first-parent -- fi
对于某些文件,在 Git Python 中 g.log() 指令会给出错误,但对于同一文件,如果我在终端上执行 [$git log -- ],则工作正常。终端上的以下命令运行良好: $git log
我有 2 个程序: #include "file1" int main(void) { return (1); } 其中 file1 只是一个空文件,位于与程序相同的目录中。 然后我有: #i
我正在尝试制作一个页面来显示添加到数据库中的产品。 我需要使用“foreach”来自动显示所有产品。 我被困在一个部分,我需要显示每个产品的下载数量。执行此操作的唯一方法是计算下载表中包含产品文件名的
这是我的代码,它执行得很好并且符合预期。我的问题是,“file_name”如何不抛出错误,即使它没有在代码的前面定义。我确认它不是关键字。 import os def rename_files():
实际上我有两个命令: 来源FILE_NAME 安装ABCD 在执行第二个命令之前,我需要执行第一个命令。我使用 Runtime.getRuntime().exec(cmd) 方法执行这两个命令,但第二
这个问题在这里已经有了答案: How do I mock the filesystem in Python unit tests? (5 个回答) 关闭去年。 我有一个打开 csv 文件并设置标题的源
我正在尝试在Flask中创建一个基本项目,并且在执行此操作时遇到此错误: Error: Could not import "file_name" in flask 这是我尝试运行的代码: from f
这个问题来自spoj。请参阅this供提问。正如您所看到的,我的逻辑很简单。如果我将动态形式的数组大小更改为静态数组大小,则代码将执行并请求整数,并无限期地继续执行,同时它应该运行测试用例的数量。但是
我正在尝试编写一个简单的脚本,该脚本将从命令行获取文件名并将该文件转换为另一种格式。下面是我开始使用的一小段简单代码,但我一直收到此错误:NameError:未定义名称“file_name” 这是代码
我有一个名为 schedule.py 的文件: class SchedGen: """ Class creates a pseudo random Schedule. With 3/4
当使用 text_file_backend 并设置 collector 时,是在 keywords::target 目录中创建的日志文件还是 collector 将旧日志文件移到那里? 如果 coll
我被指示编写一段代码来执行一个函数,然后调用另一个函数将结果打印到文件中。我使用“a”运算符是因为打印函数被多次调用。 每当我使用 printf 运行该函数时,所有内容都会完美地打印到控制台。当我使用
我一直在 Ubuntu 终端上编译和运行我的程序,就像这样: javac ev.java java xyz.class file_name.txt 我如何为此制作一个 makefile? 我已经学习了
当我尝试在 Debug模式下运行代码时,一切正常,但当我尝试在 Release模式下运行时,出现错误“file_name != nullptr”(错误来自 fopen)。我知道错误是什么意思,但我不知
您能介绍一下ChannelSftp.get("file_name")的内部工作原理吗?如果频繁使用该函数,使用该函数从文件列表(600个10kb的文件)中获取单个文件会导致Tomcat8内存泄漏问题吗
我是一名优秀的程序员,十分优秀!