首页 > 360笔试8月24日下午场 第二题
头像
container_of
编辑于 2020-08-24 15:36
+ 关注

360笔试8月24日下午场 第二题

求大佬解释我是不是理解错了题目了,求指点,第一次发这类帖子。感谢!
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int num;
    cin >> num;
    int score = 0;
    vector<int> v1,v2;
    while(num--) {
        int m,n;
        cin >> m >> n;
        if(n == 1) v1.push_back(m);
        else v2.push_back(m);
    }
    
    for(int i=0; i<v2.size(); i++) {
            score += v2[i];
        }
        
    sort(v1.begin(),v1.end(),greater<int>());
    for(int i=0; i<v1.size(); i++) {
        if(score <= v1[i]) score += v1[i];
        else {
            score *= 2;
        }
    }
    cout << score <<endl;
    return 0;
}

再求问第一题我这样做法是不是很傻?
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    while(cin>>str) {
        int n = str.size();
        int cnt = 0;
        if(n%2 == 0){
            for(int i=0,j=n-1; i<j; i++,j--) {
                if(str[i] == str[j] && (str[i] == 'A' || str[i] == 'H'||str[i] == 'I'||str[i] == 'M'||str[i] == 'O'||str[i] == 'T'
                ||str[i] == 'V' ||str[i] == 'W' ||str[i] == 'X' ||str[i] == 'Y'||str[i] == 'U'))
                cnt++;
            }
            if(cnt == n/2) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
        else {
            for(int i=0,j=n-1; i<=j; i++,j--) {
                if(str[i] == str[j] && (str[i] == 'A' || str[i] == 'H'||str[i] == 'I'||str[i] == 'M'||str[i] == 'O'||str[i] == 'T'
                ||str[i] == 'V' ||str[i] == 'W' ||str[i] == 'X' ||str[i] == 'Y'||str[i] == 'U'))
                cnt++;
            }
            if(cnt == n/2+1) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }

    return 0;
}


全部评论

(3) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐