AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

练习

作者: 作者的头像   Tie ,  2019-09-20 13:28:53 ,  所有人可见 ,  阅读 751


2


a small hedge fund

  • 题目
    Given weights of N lions, find their relativate ranks and the lions with the top three largest weights, which will be termed: “Alpha”, “Beta”,”Gamma”.
  • Example:
    Input: [90,85,80,75,70]
    Output: [“Alpha” ,”Beta”, “Gamma”, “4”,”5”]
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
const int N = 100010;

int n;
int lions[N];
string index[N]; //i的index

int main()
{
    vector<int> original;
    cin >> n;
    for (int i = 0; i < n; i ++ ) 
    {
        cin >> lions[i];
        original.push_back(lions[i]);
    }

    sort(lions, lions + n);
    reverse(lions, lions + n);

    for (int i = 0; i < n; i ++ )
    {
        if (lions[0] == original[i]) index[i] = "Alpha";
        if (lions[1] == original[i]) index[i] = "Beta";
        if (lions[2] == original[i]) index[i] = "Gamma";
        for (int j = 3; j < n; j ++ )
            if (lions[j] == original[i]) index[i] = to_string(j + 1);
    }

    for (int i = 0; i < n; i ++ ) 
    {
        cout << index[i] << " ";
    }

    return 0;

}
  • 题目
    Given an array nums, write a function to move all 0’s to the end of it while maintainning the relative order of the non-zero elements
  • Example:
    Input: [0,1,0,3,12]
    Output: [1,3,12,0,0]
#include <iostream>
#include <vector>

using namespace std;

const int N = 100010;
int n;
int a[N];
int q[N];
int hh = 0, tt = n - hh - 1;

int main()
{

    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> a[i];


    for (int i = 0; i < n; i ++ )
    {
        if (a[i] == 0) q[tt -- ] = a[i];
        if (a[i] != 0) q[hh ++ ] = a[i];
    }

    for (int i = 0; i < n; i ++ ) cout << q[i] << " ";

    return 0;

}
#include <iostream>
#include <vector>
using namespace std;

vector<char> g;
string line;
int main()
{
    while(getline(cin, line))
    {
        for (int i = 0; i < line.size(); i ++ )
            for (int j = 0; j < i + 1; j ++ )
                g.push_back(line[j]);
    }

    for (int i = 0; i < g.size(); i ++ ) cout << g[i];

    return 0;
}
#include <iostream>
#include <algorithm>

using namespace std;
const int N = 100010;

int n;
int a[N];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> a[i];

    reverse(a + 1, a + n - 1);

    for (int i = 0; i < n; i ++ ) cout << a[i] << " ";
    return 0;

}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息