我正在尝试编写一个简单的python算法来解决这个问题.你能帮我弄清楚为什么我的代码不能正常工作:
问题:
Jakub正在尝试一维键盘.它由一排键组成.任意两个相邻键之间的距离为1.每个键包含一个不同的英文字母.Jakub只用一根手指在键盘上打字.他想知道在键入给定单词时他将要移动手指的最小总距离是多少.
例如,如果键盘的唯一行是"qwertyuiop",并且Jakub想要输入单词"potter",他将不得不将他的手指从'p'移动到'o'(距离1),从'o'移动到' t'(距离4),从't'到't'(距离0),从't'到'e'(距离2)和从'e'到'r'(距离1),总距离1 + 4 + 0 + 2 + 1 = 8.
给你一个字符串键盘和一个字符串单词,描述键盘和Jakub想要写的单词.返回他需要移动手指的最小距离,以便在键盘上键入单词.
我的代码:
def typingDistance (keyboard, word):
a=keyboard.find(word[0][:1])
res=0
for i in word:
if keyboard.find(i) != a:
res+=abs(a-i)
a = keyboard.find(i)
return res
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#define X (Y+4)
#define Y (X+3)
int main(void) {
printf("%d\n",4*X+2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误:未定义的符号'X'.
我在OCaml中有这个非常基本的类:
class handler rule callback methods =
object(self)
method matches test_string test_method =
let r = Str.regexp rule in
match Str.string_match r test_string 0 with
| false -> false
| true -> methods = [] || List.exists (fun nth_method -> nth_method = test_method) methods
end
Run Code Online (Sandbox Code Playgroud)
但是我无法编译它(文件是handler.ml):
File "handler.ml", line 1, characters 6-339:
Error: Some type variables are unbound in this type:
class handler :
string ->
'a -> 'b list -> object method matches : string -> 'b -> bool …Run Code Online (Sandbox Code Playgroud) 我正在玩一些c ++代码,发现如果我用4294967295(它的最大允许值)开始一个unsigned long并添加让我们说6我必须得到5,它确实!但是以下添加操作,而mod 255没有给出正确的答案.为什么会这样,以及如何避免?
Plataforms经过测试:
Windows 7,Visual Studio c ++:工作正常;
CentOS版本6.6(最终版),g ++:给出错误的答案;
请参阅下面的代码注释:
#include <stdio.h>
int main(int argc, char *argv[]) {
unsigned long s1=4294967295;
unsigned long vp=245;
unsigned long a;
unsigned long b;
unsigned long result;
/* s1 is 4294967295 + 6 wich is 5 */
s1+=6;
a=s1;
b=255*vp*s1;
result = (a + b) % 255;
printf("s1=%u , a=%u , b=%u , (a+b)=%u , (a+b)%255= %u\n", s1, a, b, a + b, result);
/* s1 is a static value 5 …Run Code Online (Sandbox Code Playgroud) 如何输出结果是早上.
#include<stdio.h>
void main()
{
printf(5+"Good Morning");
return 0;
}
output is Morning
Run Code Online (Sandbox Code Playgroud) #/bin/zsh
servers=('10.138.0.8' '10.138.0.91')
for srv in $servers; do
echo "Checking health for " $srv
echo "=========================================="
echo mntr | nc $srv 2181
done
Run Code Online (Sandbox Code Playgroud)
当我执行时,我没有循环第二个值10.138.0.91,如下所示
[devops@devops]~% ./healthcheck/zookeeper.sh
Checking health for 10.138.0.8
==========================================
zk_version 3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
zk_avg_latency 0
zk_max_latency 0
zk_min_latency 0
zk_packets_received 9
zk_packets_sent 8
zk_num_alive_connections 1
zk_outstanding_requests 0
zk_server_state follower
zk_znode_count 4
zk_watch_count 0
zk_ephemerals_count 0
zk_approximate_data_size 27
zk_open_file_descriptor_count 28
zk_max_file_descriptor_count 4096
Run Code Online (Sandbox Code Playgroud)
为什么?
我不认为我会花一个小时试图弄清楚这个......我今天取得的所有进展都是如此.
所以我正在使用看起来似乎是 - 直接手册 - erlang BIF
calendar:universal_time().
Run Code Online (Sandbox Code Playgroud)
但我明白了
35> calendar:universal_time().
** exception error: undefined function calendar:universal_time/0
Run Code Online (Sandbox Code Playgroud)
检查了我的erlang版本..所有最新版本..
33> client:cmdParse("A", [<<"24">>, <<"hellloooo">>], 56).
** exception error: undefined function calendar:universal_time/0
in function client:timeUTC/0
in call from client:cmdParse/3
34> erlang:system_info(otp_release).
"R14A"
35> calendar:universal_time().
** exception error: undefined function calendar:universal_time/0
36> calendar:universal_time()).
* 1: syntax error before: ')'
36> calendar:local_time().
** exception error: undefined function calendar:local_time/0
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?为什么不定义?
上下文:我希望给我的开发人员一些东西摆脱目前的"典型Java UI",当它至少不使用操作系统的UI或增强框架时,这是非常可怕和可怕的.
目标:我希望能够拥有一个开箱即用的优秀用户界面,并且理想情况下可定制,但主要的重点是它足以在化妆品方面增强用户体验并具有所有功能(小部件等等). .)构建复杂的可视化应用程序.
限制和理想的解决方案:我喜欢Flex的UI,但我无法在Flash技术的基础上进行构建.我想从Flex借用的最短期功能之一是他们的动画拖放和动画自动重新排序组件(手机示例,隐藏一个,另外两个并排移动,或当你拖动元素在一个窗口中,它以流畅和合乎逻辑的方式移动其他人,而ZK看起来不错,但静态地移动框或信息(http://www.zkoss.org/zkdemo/layout/business_portal)和(http:// www.zkoss.org/zkdemo/effects/drag_n_drop)
我想我的开发人员可以添加额外的编程来添加动画功能,但是如果有什么东西可以做到这一点以及更简单的方式,那就太棒了.
我是python尝试使用python打开文件的新手:
phys = "C:\\parsework\\glckpysdata.txt"
print phys
d = open(phys)
Run Code Online (Sandbox Code Playgroud)
当我跑步时,我得到:
C:\parsework\glckpysdata.txt
Traceback (most recent call last):
File "C:\py\boxtest2.py", line 28, in <module>
d = open(phys)
IOError: [Errno 2] No such file or directory: 'C:\\parsework\\glckpysdata.txt'
Run Code Online (Sandbox Code Playgroud)
我觉得我已经尝试了所有东西(phys = r"C:\ parsework\glckpysdata.txt",直接进入带双引号和单引号/反斜杠等的open命令......)似乎没有什么能阻止它读取路径带有双反斜杠.关于这个最令人沮丧的事情我在同一个脚本中有完全相同的语法,它在那里工作得很好:
thisguy = "C:\\parsework\\glckout\\"
thisguy += nam
g = open(thisguy)
Run Code Online (Sandbox Code Playgroud)
是在相同的脚本,工作正常.有人能告诉我发生了什么事吗?
所以我正在考虑制作一个GUI.我的朋友告诉我他知道如何在C#中做到这一点,所以我在设置GUI时采用了这种方法.反正有没有在Java中使用C#制作的GUI?