Replies: 0 comments 6 replies
-
老哥, 我看了你的代码 ,自己写了一遍, 为什么提交上去有三个测试点过不去,求指教。下面是代码
|
Beta Was this translation helpful? Give feedback.
-
没仔细看,但我发现我们的rank函数不同,1-4分数顺序正好相反(注意一下哪个才是最高的),可能影响到排序结果不一样。 |
Beta Was this translation helpful? Give feedback.
-
感谢回复 ,不过已经找到BUG了,粗心了rank里面写成了具体数值。
…------------------ 原始邮件 ------------------
发件人: "LuXu"<[email protected]>;
发送时间: 2019年7月4日(星期四) 晚上11:50
收件人: "OliverLew/oliverlew.github.io"<[email protected]>;
抄送: "天之☆骄子"<[email protected]>;"Mention"<[email protected]>;
主题: Re: [OliverLew/oliverlew.github.io] PAT Basic 1015. 德才论 (C语言实现) | PAT Solution in C (#17)
@603970634
没仔细看,但我发现我们的rank函数不同,1-4分数顺序正好相反(注意一下哪个才是最高的),可能影响到排序结果不一样。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Beta Was this translation helpful? Give feedback.
-
老哥,我看了你PAT1044那道题的代码有2个疑问,你有空能帮我看看吗。问题在代码的30行和54行,十分感谢。
#include <ctype.h>
#include <stdio.h>
#include <string.h>
char units[][20] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly",
"aug", "sep", "oct", "nov", "dec"};
char tens[][20] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo",
"syy", "lok", "mer", "jou"};
int Mars2Earth(char *s)
{
if(s)
{
int i;
for( i = 0; i < 13; i++) /* units digits */
if(strcmp(s, units[i]) == 0)
return i;
for(i = 1; i < 13; i++) /* tens digits */
if(strcmp(s, tens[i - 1]) == 0)
return i * 13;
}
return 0;
}
int main()
{
int N,i, m;
char line[11];
/*这里的代码是不是为了获取N的值并且吸收回车?为什么不能替换成下面这部分,替换之后提交进去答案全错
gets(line);
sscanf(line, "%d", &N);
*/
scanf("%d",&N);
fflush(stdin);
for( i = 0; i < N; i++)
{
fgets(line, 11, stdin);
if(isdigit(line[0])) /* Earth number */
{
sscanf(line, "%d", &m);
if(m / 13 && m % 13)
printf("%s %s\n", tens[m / 13 - 1], units[m % 13]);
if(m / 13 && m % 13 == 0)
printf("%s\n", tens[m / 13 - 1]);
if(m / 13 == 0)
printf("%s\n", units[m]);
}
if(isalpha(line[0])) /* Mars number */
{
m = Mars2Earth(strtok(line, " ")); /* higher digit */
m += Mars2Earth(strtok(NULL, " ")); /* lower digit */
//为什么要在空格符号加\n,把\n去掉之后在odeblocks和dev上输入elv nov的运行结果都是104(答案是115),但是提交进PAT又全通
//过了,十分疑惑,求大佬指点一下。
printf("%d\n", m);
}
}
return 0;
}
…------------------ 原始邮件 ------------------
发件人: "LuXu"<[email protected]>;
发送时间: 2019年7月4日(星期四) 晚上11:50
收件人: "OliverLew/oliverlew.github.io"<[email protected]>;
抄送: "天之☆骄子"<[email protected]>;"Mention"<[email protected]>;
主题: Re: [OliverLew/oliverlew.github.io] PAT Basic 1015. 德才论 (C语言实现) | PAT Solution in C (#17)
@603970634
没仔细看,但我发现我们的rank函数不同,1-4分数顺序正好相反(注意一下哪个才是最高的),可能影响到排序结果不一样。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Beta Was this translation helpful? Give feedback.
-
是。我目测应该是因为 https://www.geeksforgeeks.org/use-fflushstdin-c/
这个应该也是读取到的字符串含 |
Beta Was this translation helpful? Give feedback.
-
谢了哥,明白了。后面那个错误是因为我之前把32行的fgets改成了gets,gets不会读取\n,所以分割符不用加\n也能通过。而你之前用的是fgets,读取了\n,所以分割符必须加\n,否则分割出来会多一个回车字符。
…------------------ 原始邮件 ------------------
发件人: "LuXu"<[email protected]>;
发送时间: 2019年7月5日(星期五) 下午4:45
收件人: "OliverLew/oliverlew.github.io"<[email protected]>;
抄送: "天之☆骄子"<[email protected]>;"Mention"<[email protected]>;
主题: Re: [OliverLew/oliverlew.github.io] PAT Basic 1015. 德才论 (C语言实现) | PAT Solution in C (#17)
@603970634
/*这里的代码是不是为了获取N的值并且吸收回车?为什么不能替换成下面这部分,替换之后提交进去答案全错 gets(line); sscanf(line, "%d", &N); */ scanf("%d",&N); fflush(stdin);
是。我目测应该是因为scanf不读取\n,导致后面fgets出错(它会读\n),并且flush输入很罕见,Google了一下,这篇文章说后果应该是未定义的,这不是处理换行符的常见方法。
https://www.geeksforgeeks.org/use-fflushstdin-c/
m = Mars2Earth(strtok(line, " ")); /* higher digit */ m += Mars2Earth(strtok(NULL, " ")); /* lower digit */ //为什么要在空格符号加\n,把\n去掉之后在odeblocks和dev上输入elv nov的运行结果都是104(答案是115),但是提交进PAT又全通 //过了,十分疑惑,求大佬指点一下。
这个应该也是读取到的字符串含\n的关系,这样截取到的单个数字就不会有。strtok的分隔符传入多个字符时的用法,你可以了解一下。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Beta Was this translation helpful? Give feedback.
-
https://oliverlew.github.io/PAT/Basic/1015.html
题目
Beta Was this translation helpful? Give feedback.
All reactions