1
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
const int N = 110;
int num[N];
int v;
int main(){
int t;
int idx = 0;
int mx = -1;
while(cin >> t){
num[idx++] = t;
mx = t >= mx ? t : mx;
if(cin.get() == '\n') break;
}
cin >> v;
string ans = "[";
for(int i=0; i < idx; ++i)
{
if(num[i] + v >= mx){
ans += "True, ";
}else{
ans += "False, ";
}
}
ans.pop_back(); ans.pop_back();
ans.push_back(']');
cout << ans << endl;
}
3
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
class Solution {
public:
char w[6] = {'n', 'n','s','b','q','w'};
string chinese_number(int n) {
string ans = "";
int idx = 0;
while (n) {
int t = n % 10;
n /= 10;
idx++;
if (idx > 4) {
idx %= 4;
ans.push_back('w');
}
if(idx != 1 && t != 0) ans.push_back(w[idx]);
ans.push_back('0' + t);
}
if(ans.size() >= 2 && ans[ans.size()-1] == '1' && ans[ans.size()-2] == 's') ans.pop_back();
reverse(ans.begin(), ans.end());
string res = "";
int l=0, r=0;
bool isZero = false;
for(int i=0; i<ans.size(); i++){
if(ans[i] != '0'){
res.push_back(ans[i]);
isZero = false;
}
else{
if(isZero == true){
continue;
}else{
res.push_back(ans[i]);
isZero = true;
}
}
}
ans.clear();
for(int i=0; i<res.size(); i++){
if(res[i] == '0' && i+1 < res.size() && res[i+1] == 'w') continue;
else ans.push_back(res[i]);
}
while(ans.back() == '0') ans.pop_back();
return ans;
}
};
int main(){
Solution sol;
vector<pair<int, string>> vic = {
{ 11, "s1" },
{ 302, "3b02" },
{ 57049, "5w7q04s9" },
{ 600080, "6sw08s" },
{ 32000523, "3q2bw05b2s3" },
{ 12345678, "1q2b3s4w5q6b7s8" }
};
for(auto& p:vic){
string ans = sol.chinese_number(p.first);
cout << p.first << " " << p.second << ":" << ans << " isright:" << (ans == p.second) << endl;
}
}
|