作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码有什么问题?它在我的 TurboC 编译器上运行完全正常,但在 CodeChef 中给出运行时错误。
Ada 有 N 支蜡笔数组,一些蜡笔朝上,一些朝下。艾达认为,如果所有蜡笔都指向同一个方向,那么一排蜡笔就很漂亮。
一步即可翻转连续蜡笔的任意一段。翻转一段后,所有朝下的蜡笔都会朝上,反之亦然
最少需要多少步骤才能使蜡笔阵列变得漂亮?
输入
输入的第一行包含 T 测试用例的数量。每个测试用例都用包含 N 个字符的字符串 S 的一行进行描述,如果第 i 个蜡笔朝上,则第 i 个字符为“U”,如果第 i 个蜡笔朝下,则第 i 个字符为“D”。
输出
对于每个测试用例,输出一行,其中包含使所有蜡笔指向同一方向所需的最少翻转次数。
示例
输入:1呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜
输出:1
#include<stdio.h>
int main()
{
clrscr();
int t,i,j,p,c,k,ucount=0,dcount=0;
char last='0';
char cases[50][3000];
scanf("%d",&t);
for(i=0;i<t;i++)
scanf("%s",cases[i]);
for(i=0;i<t;i++)
{
for(j=0;cases[i][j]!='\0';j++)
{
if(cases[i][j]=='U' && last!='U')
{
ucount++;
last='U';
}
else if(cases[i][j]=='D' && last!='D')
{
dcount++;
last='D';
}
}
if(i==(t-1))
{
if(dcount<ucount)
printf("%d",dcount);
else
printf("%d",ucount);
}
else
{
if(dcount<ucount)
printf("%d\n",dcount);
else
printf("%d\n",ucount);
}
ucount=0;
dcount=0;
last='0';
}
return 0;
}
最佳答案
我严重怀疑 CodeChef 支持您似乎使用过的非标准 clrscr()
函数。您应该确保您使用的是本地符合标准的功能,而不是使用标准库中找不到的平台和工具特定功能的功能。
Davids-Mac-Pro:~ dhoelzer$ gcc test.c
test.c:4:1: warning: implicit declaration of function 'clrscr' is invalid in C99
[-Wimplicit-function-declaration]
clrscr();
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_clrscr", referenced from:
_main in test-171c5e.o
ld: symbol(s) not found for architecture x86_64
您可能会找到使用 conio.h
的引用,但这也不是标准的一部分。
关于c - 艾达和蜡笔 - CodeChef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45442213/
SVG 路径通常看起来像一条实线: 是否可以为 SVG 路径实现手绘(蜡笔)风格? 最佳答案 你可以尝试使用 svg 的 filter
我是一名优秀的程序员,十分优秀!