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; }
#笔试题目##360公司#