小编nik*_*hil的帖子

使用CSS将桌子设计为tic tac toe board

我打算用jQuery和PHP编写一个tic tac toe游戏.我想用CSS设置主板(一个html表)的样式.我不知道可以有选择地应用于单元格的CSS属性,以便特定单元格获得边框.我可以使用任何CSS属性,还是应该尝试不同的方法?

html标记是:

  <div id="board">
    <table>
      <tr id="row1">
        <td class="square"></td>
        <td class="square"></td>
        <td class="square"></td>
      </tr>
      <tr id="row2">
        <td class="square"></td>
        <td class="square"></td>
        <td class="square"></td>
      </tr>
      <tr id="row3">
        <td class="square"></td>
        <td class="square"></td>
        <td class="square"></td>
      </tr>
    </table>
  </div>
Run Code Online (Sandbox Code Playgroud)

css jquery html-table

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

如何使用System.in修复"IOException:Stream closed"异常?

我正在编写一个简单的程序,使用a读取和处理文件内容BufferedReader.

BufferedReader br = new BufferedReader( new InputStreamReader(System.in) );

System.out.println("Enter the file name to read");
String fileName = br.readLine();
br.close();

// Process file contents

br = new BufferedReader( new InputStreamReader(System.in) );
System.out.println("Enter another file name to read");
fileName = br.readLine();
br.close();
Run Code Online (Sandbox Code Playgroud)

但是当我调用br.readLine()另一个文件名时,我得到以下异常:

线程"main"中的异常java.io.IOException:Stream已关闭

我不明白如何System.in关闭流.我犯了什么错误,如何解决这个问题?

java system.in ioexception

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

更改链接列表

您将获得一个单链接列表a->b->c->d->1->2->3->4->e->f->g->h->5->6->7->8.你必须改变这个列表看起来像 a->1->b->2->c->3->d->4->e->5->f->6->g->7->h->8.

我的方法使用额外的列表,我们从列表中删除数字并单独存储它们.然后将列表合并在一起.有人可以建议更好的技术吗?

c++

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

帮助c ++ stl映射和运算符重载

我正在尝试使用我创建的类的stl映射,从我收集的内容,如果我想要我的类Vertex的对象作为地图的关键,我也应该重载<运算符,我尝试在Vertex类中执行此操作,文件graph.h可以在下面看到:

#ifndef GRAPH_H
#define GRAPH_H

class Vertex
{
  private:
    char vertex_name;
  public:
    Vertex(){};

    Vertex(char n)
    {
      vertex_name = n;
    }
//Method signatures
    char get_name(); 
//overloaded operators
    bool operator ==(Vertex other)
    {
      if(this.vertex_name == other.get_name())
      {
        return true;
      }
      else return false;
    }

    bool operator < (Vertex other)
    {
      if(this.vertex_name - other.get_name() < 0)
      {
        return true;
      }
      else return false;
    }
};

class Edge
{
  private:
    Vertex source,destination;
    int weight;
  public:
    Edge(){};
    Edge(Vertex v1,Vertex v2,int w)
    {
      source = v1; …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading

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

Ruby如何在对象不为nil时调用方法

我正在写一个简单的脚本,从debian网站获取一些软件包的细节.在处理没有与之关联的版本的虚拟包时遇到问题.

我收到以下错误消息

undefined method `first' for nil:NilClass (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

罪魁祸首是

version = doc.css('#content h1').text.strip.scan( /\(([^>]*)\)/).last.first
Run Code Online (Sandbox Code Playgroud)

我试着将它放入if这样的条件,但这不起作用.

if doc.css('#content h1').text 
         version = doc.css('#content h1').text.strip.scan( /\(([^>]*)\)/).last.first
      end
Run Code Online (Sandbox Code Playgroud)

所以我想知道如何检查对象是否为nil,然后尝试从中提取子字符串.

这是包含except块的整个脚本

require 'rubygems'
require 'nokogiri'
require 'open-uri'


# additional code to make sure that we can resume after a break seamlessly
last_package = 0
File.open('lastbreak','r') { |fptr| last_package = fptr.gets.to_i }
puts "Resuming from package:#{last_package}" if last_package != 0

# to read each package from packageslist.txt and fetch the required info
# also to store …
Run Code Online (Sandbox Code Playgroud)

ruby methods null undefined

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

尾部-n的高效实现

可能重复:
你如何有效地实现尾部?

我的一个朋友被问到他是如何实施的tail -n.为清楚起见,我们需要打印n指定文件的最后几行.

我想过使用n个字符串的数组并以循环方式覆盖它们.但是,如果我们给出一个10 GB文件,这种方法根本不会扩展.

有一个更好的方法吗?

c++

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

为什么我不能将Java 7菱形语法与guava ImmutableSortedMap.Builder一起使用

我正在使用java 7,这个代码片段无法编译

ImmutableSortedMap<Integer, String> INT_TO_WORD =
       new ImmutableSortedMap.Builder<>(Ordering.natural())
           .put(1, "one")
           .put(2, "two")
           .put(3, "three")
           .build();
Run Code Online (Sandbox Code Playgroud)

而这一个确实如此

ImmutableSortedMap<Integer, String> INT_TO_WORD =
       new ImmutableSortedMap.Builder<Integer, String>(Ordering.natural())
           .put(1, "one")
           .put(2, "two")
           .put(3, "three")
           .build();
Run Code Online (Sandbox Code Playgroud)

为什么我需要在rhs何时指定类型lhs?是否有更多的东西给<>操作员而不是眼睛.

java diamond-operator guava java-7

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

How do I substitute Guice modules with fake test modules for unit tests?

Here's how we are using Guice in a new application:

public class ObjectFactory {
  private static final ObjectFactory instance = new ObjectFactory();
  private final Injector injector;

  private ObjectFactory() throws RuntimeException {
    this.injector = Guice.createInjector(new Module1());
  }

  public static final ObjectFactory getInstance() {
    return instance;
  }

  public TaskExecutor getTaskExecutor() {
    return injector.getInstance(TaskExecutor.class);
  }
}
Run Code Online (Sandbox Code Playgroud)

Module1 defines how the TaskExecutor needs to be constructed.

In the code we use ObjectFactory.getInstance().getTaskExecutor() to obtain and the instance of TaskExecutor.

In unit tests we …

java spring unit-testing guice

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

是Java 8中任何用途的抽象类

我一直在阅读一些关于新Java 8功能的文章.随着Extension方法的引入,即以default关键字为前缀并提供实现的方法.

我在这里检查了几个问题,人们已经在这里这里询问抽象类和接口的差异,最大的区别似乎是抽象类允许你指定默认实现.

这是否意味着抽象类和接口之间的区别很大程度上是美化的,并且考虑到类可以实现多个接口; 它们在设计和实施方面提供了更大的灵活性.

我可以看到抽象类仍然存在,主要是为了向后兼容旧代码.我是不是正确使用未来的抽象类并仅使用接口?如果不能提供示例,只需在抽象类中定义一些字段就不算数了.我正在寻找一个引人注目的用例,与Interfaces相比,Abstract Classes仍然更适合.

另一方面,纯粹主义者会争辩说,默认实现会污染接口,这些接口应该只指定契约,行为应该总是在Concrete类中(行为的一部分可能在抽象类中).这个论点有什么价值吗?

java oop abstract-class interface java-8

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

如何从ruby中的矩阵中提取子矩阵

从ruby中的矩阵中提取子矩阵的惯用方法是什么?

我有一个矩阵,这是一个对象 Matrix

[131, 673, 234, 103, 18]
[201, 96, 342, 965, 150]
[630, 803, 746, 422, 111] 
[537, 699, 497, 121, 956] 
[805, 732, 524, 37, 331]
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个带有这样的签名的方法 matrix.submatrix(1,1)应该返回

[96, 342, 965, 150]
[803, 746, 422, 111] 
[699, 497, 121, 956] 
[732, 524, 37, 331]
Run Code Online (Sandbox Code Playgroud)

matrix.submatrix(2,2) 会回来的

[746, 422, 111] 
[497, 121, 956] 
[524, 37, 331]
Run Code Online (Sandbox Code Playgroud)

我浏览了rubydoc,但找不到能给我想要的任何方法.我如何在红宝石中做到这一点?

对于2D阵列,我想出了

def submatrix(matrix)
  submatrix = matrix.collect{|row| row.slice(1..-1)}
  # Pop off the first row
  submatrix[1..-1]
end
Run Code Online (Sandbox Code Playgroud)

我想知道我是否应该重新发明轮子,或者我可以使用Matrix类中的东西.

ruby matrix

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