问题列表 - 第22214页

如何在GLPaint示例代码中创建自己的recordedPath

我最近下载了GLPaint示例代码并查看了其中一个非常有趣的部分.有一个recordsPaths NSMutableArray,其中包含点,然后由GLPaint读取和绘制.

它在这里宣布:

NSMutableArray *recordedPaths;
recordedPaths = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Recording" ofType:@"data"]];
if([recordedPaths count])
     [self performSelector:@selector(playback:) withObject:recordedPaths afterDelay:0.2];
Run Code Online (Sandbox Code Playgroud)

这是播放代码:

 - (void) playback:(NSMutableArray*)recordedPaths {

     NSData*                    data = [recordedPaths objectAtIndex:0];

     CGPoint*               point = (CGPoint*)[data bytes];

     NSUInteger               count = [data length] / sizeof(CGPoint),

                              i;



     //Render the current path

     for(i = 0; i < count - 1; ++i, ++point)

          [self renderLineFromPoint:*point toPoint:*(point + 1)];



     //Render the next path after a short delay 

     [recordedPaths removeObjectAtIndex:0];

     if([recordedPaths count])

          [self performSelector:@selector(playback:) withObject:recordedPaths afterDelay:0.01];

}
Run Code Online (Sandbox Code Playgroud)

据我所知,recordedPaths是一个可变数组,他在其中构造CGPoint数组,然后读取和呈现.我想放入我自己的阵列,我一直遇到麻烦.

我尝试将recordedPaths声明更改为:

      NSMutableArray …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c quartz-2d

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

C到MIPS的翻译

尝试将此c代码转换为MIPS并在SPIM中运行它.

int A[100], B[100];
for(i=1; i<100; 1++){
A[i] = A[i-1] + B[i];
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,这就是我所拥有的.

    # comments are delimted by has marks

.data
A:   .word  0:100        # array of 12 integers
B:   .word  0:100        # array of 12 integers


.text
main:
    li $v0, 1       # load the value "1" into register $v0
    li $t0, 1       # load the value "1" into register $t0
    li $t1, 100     # load the value "100" into register $t1
    blt $t0, $t1, loop # branches to …
Run Code Online (Sandbox Code Playgroud)

c mips spim

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

NSUserDefault存在-iPHONE SDK

如果在那里保存NSUserDefault对象,我将如何检查"if"语句?我真的不确定怎么称呼它.所以这是一个很短的问题..

谢谢

iphone xcode cocoa nsuserdefaults

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

转义输入标记的value属性的要求

HTML标记中输入标记的value属性中字符转义的要求是什么?

它只是需要转义的双引号吗?HTML特殊字符也是?

我尝试查看W3C规范,但是我找不到有关如何将内容放入value属性的任何具体细节.

我想不用说"应该逃脱&quot;,但其他人呢?逃避和逃避似乎在我的所有浏览器中工作得很好,但我不想选择不标准的,并且最终会破坏HTML或&amp;amp;amp;amp;.

html php standards w3c

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

如何找到给定长度的k的排列?

如何找到给定长度的k的排列?

例如:

这个单词cat有3个字母:如何找到单词2的所有排列cat。结果应该是:acatcaac,等...


这不是作业问题。可以使用任何语言,但更可取的是:C / C ++或C#。我知道如何为长度LENGTH创建递归,但不为自定义大小创建递归。

language-agnostic permutation

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

检查字符串是否是Rails中的全大写字母

我想检查字符串是否是Rails中的所有大写字母.我该怎么做呢?

我正在编写自己的自定义复数辅助方法,我会传递像"WORD"这样的词,有时候会传递"Word" - 我想测试我的单词是否全部为大写所以我可以返回"词语" - 用大写字母"S" "最后,如果这个词是复数(与"WORD"相对).

谢谢!

ruby string ruby-on-rails

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

如何用3条线画一只老虎?

背景:

一位美术老师曾经给我一个设计问题,只用了3行画虎.我的想法是,我研究一只老虎并学习三条线来吸引人们仍然能够说出它是一只老虎.

这个问题的解决方案是从一只老虎的全部绘图开始并删除元素,直到你到达最容易识别为老虎的三个部分.

我喜欢这个问题,因为它可以应用于软件开发等多个学科,特别是在消除复杂性方面.

在工作中,我处理的是维护一个被黑客入侵的大型软件系统,并且变得无法维护.我的工作是消除过去开发人员造成的繁琐复杂性.

问题:

是否存在一个用于消除软件系统复杂性的固定流程 - 一种应用于该问题的简化流程模板?

language-agnostic debugging

9
推荐指数
2
解决办法
1463
查看次数

pymongo:findandmodify - 返回"no such command"

我相信pymongo(或者至少是文档)中存在一个错误,它使得无法运行findandupdate查询.

这是发生了什么.当我跑:

    result = db.command({
        'findandmodify': 'my_collection',
        'query': {'foo': 'bar'},
        'update': {'$set': {'status': 'queued'}},
    })
Run Code Online (Sandbox Code Playgroud)

实际发送到服务器的查询是:

{ 'query': {'foo': 'bar'}, 'findandmodify': 'my_collection', … }
Run Code Online (Sandbox Code Playgroud)

请注意,query参数是第一个,findandmodify第二个.

但这导致服务器抛出:

OperationFailure: command { 'query': {'foo': 'bar'}, 'findandmodify': 'my_collection', … } failed: no such cmd

因为服务器期望findandmodify是第一个(BSON dicts显然是有序的).

这有什么工作吗?

python mongodb pymongo

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

c ++中map和unordered_map之间的性能差异

我有一个简单的要求,我需要一个类型的地图.但是我需要最快的理论上可能的检索时间.

我使用了map和来自tr1的新提议的unordered_map,我发现至少在解析文件和创建地图时,通过在时间插入一个元素.

地图只花了2分钟,而unordered_map花了5分钟.

因为它将成为要在Hadoop集群上执行的代码的一部分,并且将包含约1亿个条目,我需要尽可能少的检索时间.

还有另一个有用的信息:当前正在插入的数据(键)是从1,2,......到~1,000万的整数范围.

我还可以强制用户指定最大值并使用上面的顺序,这会显着影响我的实现吗?(我听说地图是基于rb树,并且按顺序插入会导致更好的性能(或最差?))

这是代码

map<int,int> Label // this is being changed to unordered_map  
fstream LabelFile("Labels.txt");  


// Creating the map from the Label.txt  
if (LabelFile.is_open())  
{  
    while (! LabelFile.eof() )  
    {             
        getline (LabelFile,inputLine);  
        try  
        {  
            curnode=inputLine.substr(0,inputLine.find_first_of("\t"));  
            nodelabel=inputLine.substr(inputLine.find_first_of("\t")+1,inputLine.size()-1);  
            Label[atoi(curnode.c_str())]=atoi(nodelabel.c_str());  
        }  
        catch(char* strerr)  
        {  
            failed=true;  
            break;  
        }  
    }  
    LabelFile.close(); 
}
Run Code Online (Sandbox Code Playgroud)

暂定解决方案:在评论评论和答案之后,我相信动态C++阵列将是最佳选择,因为实现将使用密集键.谢谢

c++ stl tr1 data-structures

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

实例化新ArrayList时的编译错误

我有以下代码:

import java.util.*;
import java.io.*;
import java.util.*;
import java.io.*;

public class ShufflingListAndArray
{
   public static void main(String[] args) throws IOException
   {
   List <String> services = new ArrayList<String> (
   Arrays.asList("COMPUTER", "DATA", "PRINTER"));//here I have used List <String> services=new ArrayList<String>( Arrays.asList("COMPUTER", "DATA", "PRINTER"));// followed by next statement Satring s=Services.get(rnd.nextInt(Services.size()));

   String s = services.get(rnd.nextInt(services.size()));

   Collections.shuffle(list);
   //Collections.sort(list);
   System.out.println("List sorting :"+ list);
   }
} 
Run Code Online (Sandbox Code Playgroud)

当我编译这个程序时,我收到以下错误:

C:\>javac ShufflingListAndArray.java
ShufflingListAndArray.java:6: '(' or '[' expected
    List<String> services = new ArrayList<String>(
                                         ^
1 error
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个错误吗?

java list

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