每一行包括三个数据a, b, c,并且都是正整数,均小于10000。
对于输入的每一行,在单独一行内输出结果s。s=min(a,b,c)+mid(a,b,c)-max(a,b,c)。上式中,min为最小值,mid为中间值,max为最大值。
1 2 3 6 5 4 10 20 15 1 1 100 0 0 0
0 3 5 -98
#include<iostream>
using namespace std;
int main(){
int a,b,c;
while(cin>>a>>b>>c){
int max;
max=a>b?a:b;
max=max>c?max:c;
cout<<a+b+c-max-max<<endl;
}
return 0;
}
//第一次没有看别人写的,没有用编译器调试做出来的,加油! #include <iostream> #include <algorithm> using namespace std; int main(){ int a[3],b[1000],i=0; while(cin>>a[0]&&a[0]!=0){ cin>>a[1]>>a[2]; stable_sort(a,a+3); b[i]=a[0]+a[1]-a[2]; i++; } for(int j=0;j<i;j++) cout<<b[j]<<endl; return 0; }
#include<iostream> using namespace std; class CTriangle{ public: int a_,b_,c_; int Max(){ if(a_>b_&&a_>c_) return a_; if(b_>a_&&b_>c_) return b_; if(c_>a_&&c_>b_) return c_; } int Mid(){ if(a_>b_&&a_<c_) return a_; if(b_>a_&&b_<c_) return b_; if(c_>a_&&c_<b_) return c_; } int Min(){ if(a_<b_&&a_<c_) return a_; if(b_<a_&&b_<c_) return b_; if(c_<a_&&c_<b_) return c_; } void init(int a,int b,int c){ a_ = a; b_ = b; c_ = c; } }; int main(){ CTriangle Triangle; int a,b,c; while(cin >> a >> b >> c){ Triangle.init(a,b,c); cout << Triangle.Min() + Triangle.Mid() - Triangle.Max() << endl; } }
#include <iostream> #include <algorithm> using namespace std; int main() { int a[3]; while(cin >> a[0] >> a[1] >> a[2]) { if(a[0]==0 && a[1]==0 && a[2]==0) break; sort(a, a+3); cout << a[0]+a[1]-a[2] << endl; } return 0; }
//再次sort大法好 #include<bits/stdc++.h> using namespace std; int main(){ int a[3]; while(cin>>a[0]>>a[1]>>a[2]){ if(a[0]==0&&a[1]==0&&a[2]==0) break; sort(a,a+3); cout<<a[0]+a[1]-a[2]<<endl; } }
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int[] data = new int[3];
for (int i = 0; i < data.length; i++) {
data[i] = scan.nextInt();
}
Arrays.sort(data);
System.out.println(data[0] + data[1] - data[2]);
}
}
}
#include<stdio.h> int main (int argc, char *argv[]){// the shorter,the better. int a,b,c;for(;~scanf("%d%d%d",&a,&b,&c)&&a&&~printf("%d\n",a+b+c-2*((a>b?a:b)>c?(a>b?a:b):c));); }
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[] record = new int[3]; while (scanner.hasNext()) { for (int i = 0; i < 3; i++) { record[i] = scanner.nextInt(); } Arrays.sort(record); System.out.println(record[0] + record[1] - record[2]); } } }
#include <stdio.h> int main() { int a,b,c; int temp; while(scanf("%d %d %d",&a,&b,&c)!=EOF){ if(a>=c){ temp = a; a = c; c = temp; } if(a>=b){ temp = a; a = b; b = temp; } if(b>=c){ temp = c; c = b; b = temp; } printf("%d\n",a+b-c); } return 0; }
#include <iostream> #include <algorithm> using namespace std; int calDiff(int a,int b,int c){ int diff; int maxn = max({a,b,c}); diff = (a + b + c) - 2*maxn; return diff; } int main() { int a, b, c; while(cin >> a >> b >> c) { if(!(a == 0 && b == 0 && c == 0)){ cout << calDiff(a, b, c) << endl; } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Comparator; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = br.readLine()) != null) { String[] ss = s.split(" "); ArrayList<Integer> list = new ArrayList<>(); list.add(Integer.parseInt(ss[0])); list.add(Integer.parseInt(ss[1])); list.add(Integer.parseInt(ss[2])); list.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1 - o2; } }); System.out.println(list.get(0) + list.get(1) - list.get(2)); } } }