为什么long在查找三个整数的第二个最大值时显示错误的输出?

时间:2018-05-28 17:15:48

标签: c++

我是CP的新手,虽然我在这个问题中找到了三个数字中的第二个最大值,但我编写了这个代码,但是这个代码适用于int,但即使它们是相同的数据类型也不会长时间工作。 / p>

输入格式:

  • 第一行包含三元组数,N。

  • 接下来的N行各有三个空格分隔的整数。

使用的输入:

3

1 2 3

10 15 5

100 999 500

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
       int n;
       cin >>n ;
       while(n--){
          long a,b,c,d;//if i change long to int output is correct  
          scanf("%i%i%i",&a,&b,&c);
          d=min(max(a,b),max(a,c));
          printf("%i\n",d);// outputs 1 \n 10 \n 100 \n(\n means new line)
     }
    return 0;
    }

1 个答案:

答案 0 :(得分:1)

也许是因为您使用了错误的specifier%i用于int%li用于long

相关问题