小编STF*_*STF的帖子

如何向右旋转数组

我已经编写了一个程序来移动一个int数组,但找不到一种方法来移动它.如果您有任何关于如何根据空格数(int x)"旋转"我的数组的想法,你可以看看我的代码和评论,因为它目前只向左移动.谢谢

public void makeRight(int x) {
   int[] anArray = {0, 1, 2, 3, 4, 5};
   int counter = 0;
   while (counter < x) {
        int temp = anArray[0];
        for (int i = 0; i < anArray.length - 1; i++) {
            anArray[i] = anArray[i + 1];
         }

         anArray[anArray.length - 1] = temp;
         counter++;
  }
  for (int i = 0; i < anArray.length; i++){
      System.out.print(anArray[i] + " ");
  }
}
Run Code Online (Sandbox Code Playgroud)

java arrays rotation

5
推荐指数
1
解决办法
2645
查看次数

使用智能指针编写安全的复制构造函数

我想弄清楚是否有可能在std::unique_ptr内部的帮助下编写一个安全的拷贝构造函数.
这是我的代码:

#include <iostream>
#include <memory>

class A {
public:
  A():_a(10){
    std::cerr << "A() constructor" << std::endl;
  }

  A(const A& tmp){
    _a = tmp._a;
    std::cerr << "A() copy constructor" << std::endl;
  }

  ~A(){
    std::cerr << "~A()" << std::endl;
  }

  int _a;
};

class B {
public:
  B():_b(5){
    std::cerr << "B() constructor" << std::endl;
  }

  B(const B& tmp){
    std::cerr << "B() copy constructor" << std::endl;
    throw std::exception("exc");
  }

  ~B(){
    std::cerr << "~B()" << std::endl;
  }

  int _b;
};

class …
Run Code Online (Sandbox Code Playgroud)

c++ constructor smart-pointers c++11

4
推荐指数
1
解决办法
370
查看次数

如何在java字符串中查找第一个中文字符

如何在java字符串示例中查找第一个中文字符:

String str = "xing ???";
Run Code Online (Sandbox Code Playgroud)

如何在上面的str中得到第一个汉字杨的索引.谢谢!

java string chinese-locale

3
推荐指数
1
解决办法
1222
查看次数

java处理注释和静态块的顺序

之前处理的是什么 - static阻止或annotation

例如,像这样处理类的顺序是什么

@CustomAnnotation
class TemplateClass {
    static {}
}
Run Code Online (Sandbox Code Playgroud)

class有一些annotationstatic块.

java static annotations

1
推荐指数
1
解决办法
374
查看次数

将军事时间转换为标准时间(R 中的小时和分钟)

我有以下一组时间数据,必须将其转换为 12 小时格式。

-----------------
814
830
1835
1730
1442
820
1430
930
1550
1725
1615
1010
1319
1755
820
1955
1850
710
-------------------------------------
Run Code Online (Sandbox Code Playgroud)

例如:1300 = 下午 1:00

我想要这个使用 R..

如果有人告诉我这次如何使用 R 进行转换,那将会有很大帮助

time r

1
推荐指数
1
解决办法
9413
查看次数

rtl当最后一个字是英语时

当标签中的最后一个单词是英语然后(字符.例如:

label {
  direction: rtl;
  display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)
<label>php (0 ??????)</label>
Run Code Online (Sandbox Code Playgroud)

我错误的表演方向.需要: 点击查看

但显示: 点击查看

我该怎么做才能解决这个问题?它只发生在Chrome浏览器中.

编辑:通过添加修复它

&#x200F;
Run Code Online (Sandbox Code Playgroud)

之前(

谢谢你们.

html css right-to-left

1
推荐指数
1
解决办法
66
查看次数

使用阿拉伯文本进行URL解析错误

我正在尝试使用网络服务将阿拉伯语翻译成英语.构造URL时出错.我已经定义了这些案例:

enum MyErrors: Error {
    case urlParsingError(String)
    case nonDictonaryObjectReturned(Any)
}
Run Code Online (Sandbox Code Playgroud)

我的代码是:

func translateWord (text: String, ToLan:String) {

   // the text is "?????" and ToLan is "en"

    do {
        let jsonString = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=apikey&text=\(text)&lang=\(ToLan)"

        guard let url = URL(string: jsonString) else {
            throw MyErrors.urlParsingError(jsonString)
        }

        let data = try Data(contentsOf: url, options: Data.ReadingOptions())

        let jsonObject = try JSONSerialization.jsonObject(with: data,options: .allowFragments)
        guard let dictionary = jsonObject as? [AnyHashable: Any] else {
            throw MyErrors.nonDictonaryObjectReturned(jsonObject)
        }
        let result = dictionary["text"] as? [Any]
        let translattedSTR = …
Run Code Online (Sandbox Code Playgroud)

json arabic ios swift

1
推荐指数
1
解决办法
438
查看次数

是否可以使用函数原型编译项目而不是其正文?

我正在编写一个项目,我只需编写其中的一部分,问题是在if条件下我想调用别人写的函数.我有该功能的原型,但我没有它的身体.

所以链接器给我一个错误.是否可以在不注释函数调用的情况下编译代码?

这是我正在尝试编译的代码,任何帮助表示赞赏.

#include <stdio.h>

void foo(void);

int main(void)
{
    char c = getchar();
    if (c=='a'){ foo(); }   
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c compilation

0
推荐指数
1
解决办法
60
查看次数

在C中读取二进制文件

我有文件test.bin,其内容为:33 0F 13 05 54 65 73 74 20 13 06 55 73 65 72 20 31当我读到这个文件时,我得到了这样的结果:3333203046203133203035203534203635.我无法理解我做错了什么办法.

void ReadBinFile()
{
    int i;
    FILE *ptr;
    unsigned char buffer2[17];
    ptr = fopen("test.bin","r");
    fread(buffer2,sizeof(buffer2),1,ptr);

    for(i = 0; i<17; i++)
        printf("%x", buffer2[i]);
}
Run Code Online (Sandbox Code Playgroud)

c binaryfiles

0
推荐指数
1
解决办法
1675
查看次数