返回列表 發帖

[測驗紀錄] 2025/05/24

1. 基礎題庫:a043 棄保效應

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     long int a,b,c;
  6.     while(cin>>a>>b>>c)
  7.     {
  8.         pair<long long int,char> candidate[3];
  9.         candidate[0]={a,'A'};
  10.         candidate[1]={b,'B'};
  11.         candidate[2]={c,'C'};
  12.         sort(candidate,candidate+3);
  13.         if(candidate[0].first+candidate[1].first>candidate[2].first)
  14.         {
  15.             cout<<candidate[1].second<<endl;
  16.         }
  17.         else
  18.         {
  19.             cout<<candidate[2].second<<endl;
  20.         }
  21.     }
  22.     return 0;
  23. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a,b,c;
  4. struct P
  5. {
  6.     string s;
  7.     int n;
  8. };
  9. bool compare(P p1,P p2)
  10. {
  11.     return p1.n<p2.n;
  12. }
  13. int main()
  14. {
  15.     cin.tie(0);
  16.     cin.sync_with_stdio(0);
  17.     while(cin>>a>>b>>c)
  18.     {
  19.         P p[3];
  20.         p[0].s="A";
  21.         p[0].n=a;
  22.         p[1].s="B";
  23.         p[1].n=b;
  24.         p[2].s="C";
  25.         p[2].n=c;
  26.         sort(p,p+3,compare);
  27.         if(p[0].n+p[1].n>p[2].n)
  28.             cout<<p[1].s<<endl;
  29.         else
  30.             cout<<p[2].s<<endl;
  31.     }
  32.     return 0;
  33. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. struct P
  4. {
  5.     char s;
  6.     long long int v;
  7. };

  8. bool cmp(P p1,P p2)
  9. {
  10.     return p1.v<p2.v;
  11. }

  12. int main()
  13. {
  14.     cin.tie(0);
  15.     cin.sync_with_stdio(0);

  16.     long int a,b,c;
  17.     while(cin>>a>>b>>c)
  18.     {
  19.        P p[3];

  20.        p[0].s='A';
  21.        p[1].s='B';
  22.        p[2].s='C';
  23.        p[0].v=a;
  24.        p[1].v=b;
  25.        p[2].v=c;

  26.        sort(p,p+3,cmp);

  27.        if(p[0].v+p[1].v>p[2].v)
  28.         cout<<p[1].s<<endl;
  29.        else
  30.         cout<<p[2].s<<endl;
  31.     }

  32.     return 0;
  33. }
複製代碼

TOP

返回列表