2 条题解

  • 0
    @ 2025-10-13 19:14:59

    C(新答案):

    #include<stdio.h>
    #include<stdlib.h> //stdlib.h头文件提供绝对值函数abs()
    int main() {
    	int n, x, y, ans, t;
    	scanf("%d", &n);
    	for(int i = 1; i <= n; i++) {
    		scanf("%d%d", &x, &y);
    		ans = 0;
    		if(x > y) {
    			t = x;
    			x = y;
    			y = t;
    		}
    		for(int j = x + 1; j < y; j++) {
    			if(abs(j % 2) == 1) ans += j;//负奇数 % 2 等于 -1,正奇数 % 2 等于 1,在此运用abs()函数可把两种情况归类为一种。只要能将两种情况都判断到,无论什么方法都正确。
    		}
    		printf("%d\n", ans);
    	}
    	return 0;
    } 
    

    信息

    ID
    621
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    提交数
    144
    已通过
    30
    上传者