本文整理汇总了C++中ArrayType::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayType::cbegin方法的具体用法?C++ ArrayType::cbegin怎么用?C++ ArrayType::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayType
的用法示例。
在下文中一共展示了ArrayType::cbegin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindTheMissingNumberSum
/** Find the Missing Number
*
* @reference https://www.geeksforgeeks.org/find-the-missing-number/
*
* You are given a list of n-1 integers and these integers are in the range of 1 to n.
* There are no duplicates in list. One of the integers is missing in the list.
* Write an efficient code to find the missing integer.
*
* @complexity O(n)
*/
auto FindTheMissingNumberSum(const ArrayType &integers) {
assert(not integers.empty());
const auto N = integers.size() + 1u;
const auto sum = N * (N + 1) / 2;
return std::accumulate(integers.cbegin(), integers.cend(), sum, std::minus<ArrayType::value_type> {});
}
示例2: make_pair
std::pair<int, int> FindSubarrayWithGivenSum(const ArrayType &integers,
const ArrayType::value_type SUM) {
assert(not integers.empty());
auto start = integers.cbegin();
auto current_sum = *start;
for (auto i = start + 1; i != integers.cend(); ++i) {
while (current_sum > SUM and start < i - 1) {
current_sum -= *start++;
}
if (current_sum == SUM) {
return std::make_pair(start - integers.cbegin(), i - integers.cbegin() - 1);
}
current_sum += *i;
}
return NOT_FOUND;
}
示例3: RearrangeArrayInPlace
auto RearrangeArrayInPlace(ArrayType elements) {
for (ArrayType::size_type i = 0; i < elements.size(); ++i) {
elements[elements[i] % elements.size()] += i * elements.size();
}
std::transform(elements.cbegin(), elements.cend(),
elements.begin(), [&elements](const ArrayType::value_type v) {
return v / elements.size();
});
return elements;
}
示例4: SumTailRecursive
auto SumTailRecursive(const ArrayType &elements) {
return SumTailRecursive(elements.cbegin(), elements.cend());
}
示例5: SumRecursive
auto SumRecursive(const ArrayType &elements) {
return SumRecursiveHelper(elements.cbegin(), elements.cend());
}