基本上,我必须使用选择排序来对string[]. 我已经完成了这部分,但这是我遇到的困难。
然而,排序应该是不区分大小写的,这样“天线”就会出现在“木星”之前。ASCII 从大写到小写排序,所以没有办法只交换排序字符串的顺序吗?或者有更简单的解决方案吗?
void stringSort(string array[], int size) {
int startScan, minIndex;
string minValue;
for(startScan = 0 ; startScan < (size - 1); startScan++) {
minIndex = startScan;
minValue = array[startScan];
for (int index = startScan + 1; index < size; index++) {
if (array[index] < minValue) {
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以指出我在这段代码中尝试做的事情,因为SecondLoop线程根本无法访问?只有删除while(true)循环才能访问它.
#include <iostream>
#include <thread>
using namespace std;
void Loop() {
while(true) {
(do something)
}
}
void SecondLoop() {
while(true) {
(do something)
}
}
int main() {
thread t1(Loop);
t1.join();
thread t2(SecondLoop);
t2.join(); // THIS THREAD IS UNREACHABLE AT ALL!
return false;
}
Run Code Online (Sandbox Code Playgroud)
我使用多线程的原因是因为我需要同时运行两个循环.
如何检测3D点是否在锥体内?
Ross cone = (x1, y1, h1)
Cone angle = alpha
Height of the cone = H
Cone radius = R
Coordinates of the point of the cone = P1 (x2, y2, h2)
Coordinates outside the cone = P2( x3, y3, h3)
Result for point1 = true
Result for point2 = false
Run Code Online (Sandbox Code Playgroud) 我从Matlab调用Google Protocol Buffers Java API.这很好用,但我遇到了很大的性能瓶颈.大部分数据作为以下类型的对象返回:
java.util.Collections$UnmodifiableRandomAccessList
Run Code Online (Sandbox Code Playgroud)
它们实际上包含一个浮点列表.我需要将其转换为Matlab矩阵.到目前为止,我发现的最佳方法是致电:
cell2mat(cell(Q.toArray()))
Run Code Online (Sandbox Code Playgroud)
但是,这一行是代码中的巨大性能瓶颈.
注意我知道Google Protocol Buffers的FarSounder Matlab解析器生成器,遗憾的是这些生成器非常慢.请参阅下文,了解我的问题(YMMV)的一些粗略基准速度.高是好的.
如果不是为了将转换java.util.Collections$UnmodifiableRandomAccessList
为Matlab矩阵的开销,那么从Matlab调用Java API的方法看起来很有希望.
有没有更好的方法将这个Java对象转换为Matlab矩阵?
请记住,返回此类型的方法是自动生成的代码.
我使用brew 0.9.5,我安装了rbenv 0.4.0和ruby-build,用于ruby 2.1.2.
一段时间没有触及任何东西,并且在几次osx更新之后:
bundle
Run Code Online (Sandbox Code Playgroud)
给:
/usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/2.1.0/x86_64-darwin13.0/digest/sha1.bundle, 9): Library not loaded: @@HOMEBREW_PREFIX@@/opt/openssl/lib/libcrypto.1.0.0.dylib (LoadError)
Referenced from: /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/2.1.0/x86_64-darwin13.0/digest/sha1.bundle
Reason: image not found - /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/2.1.0/x86_64-darwin13.0/digest/sha1.bundle
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/definition.rb:1:in `<top (required)>'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler.rb:153:in `definition'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/cli/install.rb:76:in `run'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/cli.rb:146:in `install'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/vendor/thor/command.rb:27:in `run'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/vendor/thor/invocation.rb:121:in `invoke_command'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/vendor/thor.rb:363:in `dispatch'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/vendor/thor/base.rb:440:in `start'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/cli.rb:9:in `start'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/bin/bundle:20:in `block in <top (required)>'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/friendly_errors.rb:5:in `with_friendly_errors'
from /usr/local/Cellar/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/bin/bundle:20:in `<top (required)>'
from /usr/local/Cellar/rbenv/versions/2.1.2/bin/bundle:23:in `load'
from /usr/local/Cellar/rbenv/versions/2.1.2/bin/bundle:23:in `<main>'
Run Code Online (Sandbox Code Playgroud)
我试过brew uninstall openssl && brew …
它看起来像python完美的工作......
$ python
Python 2.7.8 (default, Aug 24 2014, 21:26:19)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Run Code Online (Sandbox Code Playgroud)
但python -v打印出各种垃圾:
$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py
import site # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py
import os # precompiled from /u
<..................>
/usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.pyc
# /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_osx_support.pyc matches /usr/local/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_osx_support.py …Run Code Online (Sandbox Code Playgroud) 我在Mac OS上安装sbt使用brew install sbt.
build.sbt我的应用程序的文件如下所示:
import NativePackagerKeys._
packageArchetype.java_application
name := """scala-getting-started"""
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
"com.twitter" % "finagle-http_2.10" % "6.18.0",
"postgresql" % "postgresql" % "9.0-801.jdbc4"
)
Run Code Online (Sandbox Code Playgroud)
我真的无法理解的是,如果我想编译当前的应用程序sbt需要获取包org.scala-sbt.
Hanfeis-MacBook-Pro:scala-getting-started hanfeisun$ sbt compile stage
Getting org.scala-sbt sbt 0.13.5 ...
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13.5/jars/sbt.jar ...
[SUCCESSFUL ] org.scala-sbt#sbt;0.13.5!sbt.jar (7322ms)
Run Code Online (Sandbox Code Playgroud)
不该org.scala-sbt当我安装已经安装sbt的brew install sbt?为什么sbt需要再次下载自己的软件包?
有没有人有这个想法?谢谢!
我正在编写一个Mac OS程序,我有以下几行:
os.execute("cd ~/testdir")
configfile = io.open("configfile.cfg", "w")
configfile:write("hello")
configfile:close()
Run Code Online (Sandbox Code Playgroud)
问题是,它只在脚本当前目录中创建配置文件,而不是我刚刚进入的文件夹.我意识到这是因为我使用控制台命令来更改目录,然后指示Lua代码来编写文件.为了解决这个问题,我将代码更改为:
configfile = io.open("~/testdir/configfile.cfg", "w")
Run Code Online (Sandbox Code Playgroud)
但是我得到以下结果:
lua: ifontinst.lua:22: attempt to index global 'configfile' (a nil value)
stack traceback:
ifontinst.lua:22: in main chunk
Run Code Online (Sandbox Code Playgroud)
我的问题是,使用IO.Open在我刚刚在用户主目录中创建的文件夹中创建文件的正确方法是什么?
我很欣赏我在这里犯了一个新手的错误,所以如果你浪费你的时间我会道歉.
我想在MATLAB中修改一个计算给定公式的代码,我想用与给定公式中相同的符号编写代码.在公式中,我有两个不同的函数,它们具有相同的名称,但只有参数的数量不同:Kn(a,b)和Kn(a).
MATLAB中有没有一种方法可以像c ++一样定义重载函数?
我有一个名为的数组skj.skj包含200万行数字(2000000x1 uint32).
我想计算以下内容
string_skj = num2str(skj);
Run Code Online (Sandbox Code Playgroud)
当我运行上述行时大约需要1分钟,是否有更快的方法呢?