RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-611212

deado's questions

Martin Hope
deado
Asked: 2024-08-08 01:06:03 +0000 UTC

单调数的个数

  • 4

假设递增数是指从左向右读时,其数字始终不小于前面的数字,例如:234559。

相反,在递减的数字中,从左到右的数字不会增加,例如:97732。

您不必成为新高斯也能理解一百以下的所有数字都属于这两个类别之一。

现在您需要创建一个函数来计算此类数字的数量,最多可达 10 的 n 次方(函数参数)。

全部的 以下
1 1
10 10
100 100
第475章 1000
第1675章 10000
4954 100000
12952 1000000
#include <string>
#include <cmath>
using namespace std; 
unsigned long long total_inc_dec(unsigned int n) {
  string curr_num; unsigned long long total = 0; int isInc;
  for (int i = 0; i < pow(10, n); i++) {
    curr_num = to_string(i);
    if (int(curr_num.length()) <= 2) {++total;}
    else {
      for (int it = 0; it < int(curr_num.length()); it++) {
        if (it==0) {
          if (curr_num[it] < curr_num[it+1]) {isInc = 1;}
          if (curr_num[it] == curr_num[it+1]) {isInc = 0;}
          if (curr_num[it] > curr_num[it+1]) {isInc = -1;}
        }
        else {
          if (curr_num[it] < curr_num[it+1]) {
              switch(isInc) {
                case 1:
                    if (it == int(curr_num.length()) - 2) {
                        ++total;
                    }
                    break;
                case 0: 
                    isInc = 1;
                    if (it == int(curr_num.length()) - 2) {
                        ++total;
                    }
                    break;
                case -1: 
                    it = int(curr_num.length());
                    break;
              }
          }
          if (curr_num[it] == curr_num[it+1]) {
              if (it == int(curr_num.length()) - 2) {
                ++total;
              }
          }
          if (curr_num[it] > curr_num[it+1]) {
            switch(isInc) {
                case -1:
                    if (it == int(curr_num.length()) - 2) {
                        ++total;
                    }
                    break;
                case 0: 
                    isInc = -1;
                    if (it == int(curr_num.length()) - 2) {
                        ++total;
                    }
                    break;
                case 1: 
                    it = int(curr_num.length());
                    break;
            }
          }
        }
      }
    }
  }
  return total;
}

今天我几乎第一次听到“优化”这个词。我真的不知道该怎么做。

c++
  • 1 个回答
  • 91 Views
Martin Hope
deado
Asked: 2024-08-05 14:59:17 +0000 UTC

帮助! Codewars C++ [关闭]

  • 1
关闭这个问题是题外话。目前不接受对此问题的答复。

该问题已结束,因为在俄语版 Stack Overflow上,习惯上只用俄语提问。请将您的问题翻译成俄语或使用英语的 Stack Overflow。

昨天关门了。

改进问题

任务:

取一个数字:56789。向左旋转,你得到67895。

保留第一位数字并向左旋转其他数字:68957。

保留前两位数字并旋转其他数字:68579。

保留前三位,向左旋转其余的:68597。现在已经结束了,保留前四位,只剩下一位,旋转后的数字就是它本身。

您有以下数字序列:

56789 -> 67895 -> 68957 -> 68579 -> 68597

并且您必须返回最大的:68957。

任务编写函数 max_rot(n) 给定一个正整数 n,返回与上面的示例类似的旋转的最大数量。

和我的代码:

#include <string>
#include <vector>
#include <sstream>
using namespace std;

class MaxRotate
{
public:
  static long long maxRot(long long n) {
    vector<char> n_char = new vector<char>;
    vector<long long> total_arr;
    string ntos = to_string(n);
    istringstream StoC(ntos);
    while (StoC) {
      n_char.push_back(StoC);
    }
    // first operation
    n_char.front() = n_char.end();
    total_arr.push_back(stoi(to_string(n_char)));
    // second operation
    n_char[1] = n_char.end();
    total_arr.push_back(stoi(to_string(n_char)));
    // third operation
    n_char[2] = n_char.end();
    total_arr.push_back(stoi(to_string(n_char)));
    // fourth operation
    n_char[3] = n_char.end();
    total_arr.push_back(stoi(to_string(n_char)));
    //returning the greatest
    long long g;
    for (int i = 0; i < (int)total_arr.size(); i++) {
      if (i == 0) {
        g = total_arr[0];
      }
      else {
        if (g < total_arr[i]) {
          g = total_arr[i];
        }
      }
    }
    return g;
  }
};

我已经尝试编写这段代码很长时间了,但每次错误都越来越多。

c++
  • 1 个回答
  • 42 Views
Martin Hope
deado
Asked: 2024-08-04 21:22:14 +0000 UTC

解决问题的代码 C++ codewars

  • 5

任务:

“在这个小作业中,您将获得一串空格分隔的数字,并且必须返回最大和最小的数字。

Examples
   highAndLow("1 2 3 4 5");  // return "5 1"
   highAndLow("1 2 -3 4 5"); // return "5 -3"
   highAndLow("1 9 3 4 -5"); // return "9 -5"

注意 所有数字都是有效的 Int32,无需验证。输入字符串中始终至少有一个数字。输出字符串必须是由一个空格分隔的两个数字,最大的数字在前。”

我的代码:

#include <string>
using namespace std;
string highAndLow(const string& numbers){
  string::iterator it;
  int h, l;
  for(it = &numbers.begin(); it != &numbers.end(); ++it) {
    if (it == &numbers.begin()) {
      h = (int*)it;
      l = (int*)it;
    }
    else {
      if (h < (int)it) {
        h = (int*)it;
      }
      if (l > (int*)it) {
        l = (int*)it;
      }
    }
    return string(h + " " + l + "\n");
  }
}

我刚开始学习SRR几天,请不要太严厉地评判。

c++
  • 1 个回答
  • 55 Views
Martin Hope
deado
Asked: 2024-07-31 21:52:28 +0000 UTC

段错误的原因尚不清楚

  • 6
class Item {
    public:
    
    
    string Name = "null";
    int Price = 0;
    
    
    Item(string aName, int aPrice) {
        Name = aName;
        Price = aPrice;
    }
};

class Map {
    public:
    Item List[10];
};
int main() {
    Map* HashTable;
    cout << HashTable->List[0].Name; 
    return 0;
}

我已经尝试解决这个问题很长时间了。我什么都不明白。

main.cpp:25:11:错误:没有匹配的函数可用于调用“Item::Item()”25 |地图() { | –

c++
  • 1 个回答
  • 39 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5