问题列表 - 第41247页

Java - 绘制递归调用的图表

我有以下代码

public static int unknown(String x)
{
if ((x.length()==1) && (x.equals("1")))
    return 1;
else if ((x.length()==1) && (x.equals("0")))
        return 0;
else if (x.charAt(x.length()-1)=='1')
     return 1+ 2*unknown(x.substring(0,x.length()-1));
else
    return 0+2*unknown(x.substring(0,x.length()-1));
}
Run Code Online (Sandbox Code Playgroud)

我的教授说我必须绘制递归调用的图表.他在谈论什么样的图表?我应该如何展示它?谢谢.

PS正在调用的字符串是"101011",或43.

-担

java recursion

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

Android内部存储,如何正确解析JSON文本文件

我正在创建一个Android应用程序,它使用JSON对象创建一个文本文件并将其写入内部存储.我有以下代码来做到这一点:

JSONObject myJSON = new JSONObject();
//Set the JSON object with website, length and Id (time-stamp)
try {
    myJSON.put("Length", trim)
    .put("Website", data)
    .put("Id", tx);
} catch (JSONException e1) {
    e1.printStackTrace();
}

//Convert JSON object to a string and add a comma
String myJSONString = myJSON.toString();
myJSONString += ", ";

try {
     FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_APPEND);
     fos.write(myJSONString.getBytes());
     fos.close();
     //Log.d(TAG, "Written to file");

} catch (Exception e) {
    Log.d(TAG, "cought");
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

现在我得到一个看起来像这样的文本文件:

{"Id":"20101211T155146","Length":10}, {"Id":"20101211T155155","Length":10},
{"Id":"20101211T155203","Length":10}, {"Id":"20101211T155252","Length":10}, 
Run Code Online (Sandbox Code Playgroud)

我现在想在JSON文件中收集这些数据.该应用程序需要编写,存储和检索JSON.问题是当我使用以下方法解析文件中的JSON对象时:

String x = …
Run Code Online (Sandbox Code Playgroud)

android json

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

颠倒阵列?

我不是在谈论array_flip(),我想在没有数字/字母顺序的基础上反转数组,只是倒置.

例:

array('music','television','hollywood');
Run Code Online (Sandbox Code Playgroud)

将会:

array('hollywood','television','music');
Run Code Online (Sandbox Code Playgroud)

谢谢!

php arrays

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

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

在Mac上为Mono配置PKG_CONFIG_PATH

我正在使用Mac OS X,我正在尝试从Mono Basics网站运行以下代码:

using Gtk;
using System;

class Hello {
    static void Main()
    {
        Application.Init ();

        Window window = new Window ("helloworld");
        window.Show();

        Application.Run ();
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我用以下命令编译:

    gmcs hellogtk.cs -pkg:gtk-sharp-2.0
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Package gtk-sharp-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk-sharp-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk-sharp-2.0' found
error CS8027: Error running pkg-config. Check the above output.
Run Code Online (Sandbox Code Playgroud)

我不知道软件包目录在我的计算机上的位置,所以我不知道将PKG_CONFIG_PATH设置为什么.你们有没有人在Mac OS X上使用Mono,你能指出我正确的方向,这些文件在哪里以及我应该将PKG_CONFIG_PATH设置为什么?

macos mono path

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

Memcached安装问题

我正在尝试将memcached安装到REDHAT Enterprise 5.5 x86_64

我试过了:

root@sv [~]# yum -y install memcached
Run Code Online (Sandbox Code Playgroud)

然后收到以下错误

--> Running transaction check
---> Package memcached.x86_64 0:1.4.5-1.el5.rf set to be updated
--> Processing Dependency: perl(AnyEvent) for package: memcached
--> Processing Dependency: perl(AnyEvent::Socket) for package: memcached
--> Processing Dependency: perl(AnyEvent::Handle) for package: memcached
--> Processing Dependency: perl(YAML) for package: memcached
--> Processing Dependency: perl(Term::ReadKey) for package: memcached
--> Processing Dependency: libevent-1.1a.so.1()(64bit) for package: memcached
--> Running transaction check
---> Package compat-libevent-11a.x86_64 0:3.2.1-1.el5.rf set to be updated
---> Package …
Run Code Online (Sandbox Code Playgroud)

memcached yum

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

去除"前缀"的NSSortDescriptor

我有一堆艺术家存储在CoreData中,并希望按名称对它们进行排序,但忽略前缀"the".因此,例如"甲壳虫乐队"将被归类为"甲壳虫乐队",有点像iTunes/iPod所做的那样.

所以我尝试cleanName在Artist模型中添加一个自定义属性,以便它可以用于排序:

NSSortDescriptor *sortByName = [[NSSortDescriptor alloc] initWithKey:@"cleanName" ascending:YES];
Run Code Online (Sandbox Code Playgroud)

这显然会降低应用程序,因为cleanName它不是SQLEntity的属性:

...keypath cleanName not found in entity <NSSQLEntity Artist id=1>
Run Code Online (Sandbox Code Playgroud)

我知道我可以在商店中保存cleanName,但这对我来说似乎不对.一个新的属性只是将名称剥离了"the"前缀?真?

所以相反,我尝试使用自定义compareObject:toObject:implementation来子类化NSSortDescriptor:

- (NSComparisonResult)compareObject:(Artist*)artist1 toObject:(Artist*)artist2 {

 NSString *cleanString1 = [artist1.name stringByReplacingOccurrencesOfString:@"the " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [artist1.name length])];
 NSString *cleanString2 = [artist2.name stringByReplacingOccurrencesOfString:@"the " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [artist2.name length])];

 return [artist1.cleanName compare:artist2.cleanName options:NSCaseInsensitiveSearch];
}
Run Code Online (Sandbox Code Playgroud)

当我添加一位新艺术家,将"披头士乐队"添加到我的商店时,这就有效.艺术家被分类为"披头士乐队"并显示在我的"B"部分内.但是一旦我退出应用程序并重新启动它,我就会收到以下错误,并且tableview只保持空白:

sectionIndex A for Apparat
sectionIndex B for Bonobo
sectionIndex M for Misteur Valaire
sectionIndex M for Moderat
sectionIndex P for Paul Kalkbrenner
sectionIndex …
Run Code Online (Sandbox Code Playgroud)

sorting iphone core-data tableview

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

iPhone模拟器在发布后立即挂起

每当我尝试在Xcode中启动iphone模拟器(通过Build&Run)时,模拟器就会出现并立即挂起沙滩球.

我已经尝试构建并运行一个空白项目,重新启动Xcode和我的机器,到目前为止没有任何帮助.我正在运行Snow Leopard 10.6.5,Xcode 3.2.5和Simulator 4.2.

我的控制台中出现的唯一错误是:

12/11/10 6:03:02 PM installd[1134] CFPreferences: user home directory at file://localhost/Users/Old%20Mac/Library/Application%20Support/iPhone%20Simulator/4.2/ is unavailable. User domains will be volatile.
12/11/10 6:03:42 PM com.apple.launchd.peruser.502[117] (com.apple.iPhoneSimulator:com.apple.mobile.installd[1155]) Exited with exit code: 255
12/11/10 6:03:42 PM com.apple.launchd.peruser.502[117] (com.apple.iPhoneSimulator:com.apple.mobile.installd) Throttling respawn: Will start in 10 seconds
Run Code Online (Sandbox Code Playgroud)

模拟器在黑屏上保持冻结:![冻结!]

任何帮助将非常感谢 - 谢谢!

iphone ios4 ios-simulator

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

如何初始化struct?

我应该在我的任意结构中实现什么成员才能使以下任务成为可能:

public struct MyStruct {
   String s;
   Int length;
}

MyStruct myStruct = new MyStruct { s = "Hello", length = 5 };

// Now, I want the following code to set the 's' to "Lol" and the
// length to 3 (length of "Lol"). The second part should be done
// automatically.
myStruct = "Lol"; // Or myStruct = String("Lol");
Run Code Online (Sandbox Code Playgroud)

该怎么做?

c# struct initialization

53
推荐指数
3
解决办法
11万
查看次数

线程中django的call_command问题

我想在Thread中执行django的call_method.这是示例代码:

import sys
sys.path.append("/my/django/project/path/")
import threading
import time 


# Import my django project configuration settings
from django.core.management import setup_environ
from mydjangoprojectname import settings
setup_environ(settings)

from django.core.management import call_command

class ServerStarter(threading.Thread):
    def __init__(self):
        super(ServerStarter, self).__init__()
        print "ServerStarter instance created"

    def run(self):
        print "Starting Django Server..."
        call_command("runserver", noreload=True)


if __name__ == '__main__':
    starter = ServerStarter()
    starter.start()

------------------------------
OutPut:
ServerStarter instance created
Starting Django Server...
ServerStarter instance created
Starting Django Server...
Validating models...
0 errors found
Django version 1.2.3, using settings 'mydjangoprojectname.settings'
Development …
Run Code Online (Sandbox Code Playgroud)

python django multithreading pyqt pyside

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