我坐在这里为Java主程序编写一些算法(到目前为止第一个算法).我编写levenshtein算法就好了,这要归功于wiki对于newbeginners的假代码非常好以及一个很好的教程:D
然后我决定升级到Damerau并添加额外的线,但后来我读到它不是DL算法而是OptimalStringAlignmentDistance而不是.我尝试阅读actionscript代码,以了解我需要添加什么以使其成为DL但却感到困惑.我去过不同的地方,代码看起来与Java相似,但他们都使用了错误的伪代码.
花了半天后,我放弃了,决定在这里问.是否有人可以帮助我将此代码升级到Java中的Damerau-Levenshtein?
public class LevensteinDistance {
private static int Minimum(int a, int b, int c) {
return Math.min(Math.min(a, b), c);
}
private static int Minimum (int a, int b) {
return Math.min(a, b);
}
public static int computeLevensteinDistance(String s, String t){
int d[][];
int n; // length of s
int m; // length of t
int i; // iterates through s
int j; // iterates through t
char s_i; // ith character of s
char t_j; // jth character …Run Code Online (Sandbox Code Playgroud) 我有以下网址
http://www.example.com/node/add/forum/3?gids[]=13
Run Code Online (Sandbox Code Playgroud)
我想13从我的模块中获取值.
我试过了
$_GET['gid[]']
Run Code Online (Sandbox Code Playgroud)
与
$_GET['gids%5B%5D']
Run Code Online (Sandbox Code Playgroud)
但我总是得到null.
我怎样才能做到这一点?谢谢
我们假设我们有int x = 371二进制格式101110011.我想找到最左边未设置位的索引(在这种情况下为7),以及最右边未设置位的索引(在本例中为2).这样做最有效的方法是什么?
这就是我所拥有的:
public class BitOperatons {
public static int setBit(int x, int i) {
int y = x | (1 << i);
return y;
}
public static boolean isBitSet(int x, int i) {
int y = setBit(0, i);
return y == (x & y);
}
public static int findLeftMostSetBit(int x) {
for (int i = 31; i >= 0; i--) {
if (isBitSet(x, i))
return i;
}
return -1;
}
public static int …Run Code Online (Sandbox Code Playgroud) 我知道有很多关于如何忽略目录的问题,直到现在我通常都没有遇到任何问题,但现在我遇到了一些我不理解的问题.
这是我的目录结构:
/src
/war
com.example.MyProject/
WEB-INF/
classes/
deploy/
lib/
Run Code Online (Sandbox Code Playgroud)
我想忽略目录的内容classes/,deploy/而且com.example.MyProject/,这里是我的.gitignore文件:
*.log
war/WEB-INF/classes/
war/WEB-INF/deploy/
com.example.MyProject/
Run Code Online (Sandbox Code Playgroud)
下面的文件com.example.MyProject/是自动生成的,git会忽略除名为的文件之外的所有文件com.example.MyProject.nocache.js.事实上,当我这样做时,git status我得到:
# On branch myBranch
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: .gitignore
# ......
# modified: war/com.example.MyProject/com.example.MyProject.nocache.js
Run Code Online (Sandbox Code Playgroud)
为什么git拒绝忽略该目录中的单个文件?我究竟做错了什么?
如果.metadata/在备份Eclipse工作区时跳过目录,我会失去什么?(是否有一些文档描述了Eclipse在此目录中存储的内容)?我注意到它经常变化(基本上每次我都使用Eclipse(Galileo)).
我已经看到了这个问题,但我对插件和设置的备份不感兴趣(也因为我不确定它们在重新安装我的电脑后恢复时是否能够正常工作一台新PC).我只对备份我的项目(源代码,库,可能的数据.svn和.git目录)感兴趣.那么,我可以安全地忽略该.metadata/目录吗?
我正在学习Haskell.
几天前我回答的一个问题让我对Haskell的这个练习有了灵感,这给了我实验到目前为止学到的一些东西的机会,并给我留下了问题:)
给定宽度和高度的矩形A找到最适合A的时间的矩形B,其中最佳意味着具有最小的周长.whn
我开始的基本思想是生成A的子矩形集,其面积等于div (w * h) n,然后选择具有最小周长的子矩形.
以下是我提出的这个想法的三个实现; 他们是按照时间顺序排列的:我完成了第二次后得到了第三次的灵感,这是我完成第一次后得到的(好的,有一个版本0,其中我没有使用data Rectangle,只是一个元组(x, y)):
data Rectangle = Rectangle { width :: Integer,
height :: Integer
} deriving (Show)
subRectangles :: Rectangle -> Integer -> [ Rectangle ]
subRectangles r n = [ Rectangle x y | x <- [1..w ], y <- [1..h], x * y == …Run Code Online (Sandbox Code Playgroud) 我是编程的新手,所以请放轻松我,我一直在搞乱一个简单的RSS阅读器,当用户点击文章时,尝试获取artice的链接以在webview中打开.
我找到了控制和存储链接的字符串,但是当我尝试在toast中打印链接时,链接出现但整篇文章发布日期等...我怎样才能获得自己打印的链接以及命令我隔离它后,是否需要使用链接到webview,这里是我的一些代码
RSSActivity
public class RssActivity extends ListActivity {
private RssListAdapter adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<JSONObject> jobs = new ArrayList<JSONObject>();
try {
jobs = RssReader.getLatestRssFeed();
} catch (Exception e) {
Log.e("RSS ERROR", "Error loading RSS Feed Stream >> " + e.getMessage() + " //" + e.toString());
}
adapter = new RssListAdapter(this,jobs);
setListAdapter(adapter);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, …Run Code Online (Sandbox Code Playgroud) 我想知道如何在没有arraycopy的情况下使用byte []的一部分?
用C语言
char buf[100];
int i;
for (i = 0; i < 100; i += 10) {
proc(buf + i);
}
Run Code Online (Sandbox Code Playgroud)
但在Java中,
byte[] buf = new byte[100];
int i;
for (i = 0; i < 100; i += 10) {
proc(buf + i);
}
Run Code Online (Sandbox Code Playgroud)
不行.
byte[] buf = new byte[100];
int i;
for (i = 0; i < 100; i += 10) {
byte[] temp = new byte[10];
System.arraycopy(buf, i, temp, 0, 10);
proc(temp);
}
Run Code Online (Sandbox Code Playgroud)
只有工作.
但是,我不喜欢arraycopy. …
考虑以下:
val stuff = Map[String, Int]("apple" -> 5, "orange" -> 1, "banana" -> 3, "kiwi" -> 2)
val used = 1
val rest = stuff.mapValues{
case quantity => quantity - used
}.filterNot{
case (fruit, quantity) => quantity == 0
}
Run Code Online (Sandbox Code Playgroud)
结果是
rest : scala.collection.immutable.Map[String,Int] = Map(apple -> 4, banana -> 2, kiwi -> 1)
Run Code Online (Sandbox Code Playgroud)
虽然我不是Scala的专家,但我知道该语言并不是懒惰的(与Haskell不同),因此mapValues会产生一个中间体Map,而中间体又将作为输入传递给filterNot(如果链中还有其他操作) .
如何避免这种无用的中间数据结构?
注意:我理解这个问题可以推广到其他数据结构.这里我使用的Map只是因为它是我在实际代码中使用的数据结构(尽管有其他数据:))
我想在鼠标悬停在JMenuItem上时执行一些操作.我应该使用什么样的听众?
我使用State模式来实现一个简单的有限状态机.看一下维基百科上给出的描述,更具体地说是建议的Java实现,我想知道为什么实现State接口的类(即各种状态)不是单例?
在建议的实现中,每当发生转换时都会创建一个新状态.但是,一个对象足以代表每个状态.那么,为什么每次发生转换时都会浪费时间创建一个新实例?
在java代码中:
// Define ActionListener
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JButton button = **(JButton)actionEvent.getSource();**
int red = random.nextInt(255);
int green = random.nextInt(255);
int blue = random.nextInt(255);
button.setBackground(new Color(red, green, blue));
}
};
Run Code Online (Sandbox Code Playgroud)
突出显示的(之间**和**)代码有什么作用?
我发现研究这个主题非常困难,因为我不知道要使用哪些搜索术语.:○
希望有人可以提供帮助 TIA