太戈编程16-20题AC答案(第四期)

16 最大值 入门难度

#include <iostream>
#include <algorithm>
using namespace std;
int n1,n2,n3;
int main() {
  cin>>n1>>n2>>n3;
  cout<<max(n1,max(n2,n3));
  return 0;
}

17 含k个3的数 入门难度

#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k;
  cin>>n>>k;
  long long _n=n;
  int cnt=0;
  while(n!=0){
    if(n%10==3)
      cnt++;
    n/=10;
  }
  if((cnt==k)&&(_n%19==0))
    cout<<"YES";
  else
    cout<<"NO";
  return 0;
}

18 三角形判定 入门难度

#include <iostream>
using namespace std;
int a,b,c;
int main()
{
  cin>>a;
  cin>>b;
  cin>>c;
  if (a+b>c&&a+c>b&&b+c>a)
  {
    cout<<"Yes";}
  else{
    cout<<"No";}
  return 0;
}

19 谁考了第k名 入门难度

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct e {
    string c;
    double d;
};
e a[101];
bool cmp(e a, e b) {
    return a.d > b.d;
}
int main() {
    int i, n, k;
    cin >> n >> k;
    for (i = 1; i <= n; i++) {
        cin >> a[i].c >> a[i].d;
    }
    sort(a + 1, a + 1 + n, cmp);
    cout << a[k].c << " " << a[k].d;
    return 0;
}

20 菱形变形 入门难度

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; 
    cin>>n;
    int a=n-1;
    int b=1;
    for (int i=1;i<=n;i++){ 
        for (int j=1;j<=a;j++){
            cout<<" ";
        }
        for (int k=1;k<=b;k++){
            cout<<"*";
        }
        cout<<endl;
        a--;
        b+=2; 
    }
    n--;
    int c=1;
    int d=2*n-1;
    for (int i=1;i<=n;i++){  
        for (int j=1;j<=c;j++){ 
            cout<<" "; 
        }
        for (int k=1;k<=d;k++){ 
            cout<<"*"; 
        }
        cout<<endl; 
        c++;  
        d-=2; 
    }
    return 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值