记录详情

Wrong Answer

foo.c: In function 'main':
foo.c:10:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &T); 
  ^~~~~~~~~~~~~~~
foo.c:13:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ^~~~~~~~~~~~~~~
foo.c:15:29: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   for (i = 0; i < n; i++) { scanf("%d", &num1[i]); }
                             ^~~~~~~~~~~~~~~~~~~~~
foo.c:16:29: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   for (i = 0; i < n; i++) { scanf("%d", &num2[i]); }
                             ^~~~~~~~~~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Wrong Answer 0a1,26 > 146 31 > 121 763 > 18 2ms 332.0 KiB
#2 Wrong Answer 0a1,88 > 567 398 > 163 61 > 53 19ms 292.0 KiB
#3 Wrong Answer 0a1,18 > 73 51 > 33 199 > 190 178ms 388.0 KiB

代码

#include<stdio.h>

int gcd(int m, int n) {
	if (n == 0) return m;
	return gcd(n, m % n);
}

int main() {
	int T,n,num1[9999],num2[9999],i,temp;
	scanf("%d", &T); 
	while (T > 0) { //节约出了一个变量i
		//数据的输入,其实每次只需要看最后一个数据就行
		scanf("%d", &n);
		n++;
		for (i = 0; i < n; i++) { scanf("%d", &num1[i]); }
		for (i = 0; i < n; i++) { scanf("%d", &num2[i]); }
		//for (i = 0; i < n; i++) { printf("%d", num1[i]); }
		//for (i = 0; i < n; i++) { printf("%d", num2[i]); }
		//下面开始各种情况的列举
		i--;
		if (num1[i] != 0 && num2[i] != 0) { //上下的次数相同,即有答案,则主要目标是考虑约分的问题
			if (num1[i] % num2[i] == 0 || num2[i] % num1[i] == 0) {
				if (num1[i] > num2[i]) {
					temp = gcd(num1[i], num2[i]);
				}
				else {
					temp = gcd(num2[i], num1[i]);
				}
				printf("%d %d\n", num1[i] / temp, num2[i] / temp);
			}
		}
		else if (num1[i] == 0 && num2[i] != 0) { //上面次数小于下面次数,直接是0
			printf("0 1\n");
		}
		else if (num2[i] == 0) { //上面次数大于下面次数,是正无穷
			printf("infty\n");
		}
		T--;
	}
	return 0;
}

信息

递交者
类型
递交
题目
P1000 hitwh 2019 新生赛 A ∞
语言
C
递交时间
2020-12-21 20:35:37
评测时间
2020-12-21 20:35:37
评测机
分数
0
总耗时
200ms
峰值内存
388.0 KiB