Redian新闻
>
两三年前申请过 ink plus还能申ink preferred吗?
avatar
两三年前申请过 ink plus还能申ink preferred吗?# Money - 海外理财
A*e
1
不会是只看最优解的长度吧?
那两道Excel的题,如果想不到变形十进制,写起来很繁琐。还有那个zigzag
conversion,代码不长,但数组下标很容易算错。
avatar
l*y
2
for 80k points bonus
avatar
A*e
3
写了一个zigzag,通过了测试,但运行时间在C++里算慢的,相当于C#的水平。谁有更
简洁的
解法?index计算太容易错了,必须在纸上分析清楚才行。
class Solution {
public:
string convert(string s, int nRows) {
if (nRows == 1) {
return s;
}
vector char_rank;
for (int i = 0; i < s.size(); ++i) {
char_rank.push_back({s[i], GetNewIndex(i, nRows)});
}
sort(char_rank.begin(), char_rank.end(), CharRankComp());

string result;
for (const auto& it : char_rank) {
result.push_back(it.c);
}
return result;
}

private:
struct CharRank {
char c;
pair rank;
};

struct CharRankComp {
bool operator()(const CharRank& x, const CharRank& y) {
return (x.rank.first < y.rank.first) ||
(x.rank.first == y.rank.first && x.rank.second < y.rank.
second);
}
};
// Given the global index of a char, find its new index in the zig zag
form.
pair GetNewIndex(int index, int nRows) {
const int group_size = 2 * (nRows - 1);
const int group_id = index / group_size;
const int group_idx = index % group_size;
const int row = group_idx < nRows ?
group_idx : group_size - group_idx;
const int col = group_id * (nRows - 1) +
(group_idx < nRows ? 0 : group_idx - (nRows - 1));
return make_pair(row, col);
}
};

【在 A*******e 的大作中提到】
: 不会是只看最优解的长度吧?
: 那两道Excel的题,如果想不到变形十进制,写起来很繁琐。还有那个zigzag
: conversion,代码不长,但数组下标很容易算错。

avatar
z*i
4
可以 不同的卡
别5/24就行

【在 l********y 的大作中提到】
: for 80k points bonus
avatar
l*y
5
怎么好像在版上看到说chase积点的同类型卡以后都算一种,得过bonus就不行了呢

【在 z********i 的大作中提到】
: 可以 不同的卡
: 别5/24就行

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。