最近我用c ++练习算法.在这里练习:poj
我发现两个非常混乱的问题.我写了一个MAZE类,在MAZE中有三个主要功能,它们是
int left_path();int right_path();int mini_path();
打印答案的函数:
void display(){
cout<<left_path()<<" "<<right_path()<<" ";
cout<<mini_path()<<endl;
}
Run Code Online (Sandbox Code Playgroud)
程序可以正常工作.我们看到函数display()可以很容易; 我这样写
void display(){
cout<<left_path()<<" "<<right_path()<<" "<<mini_path()<<endl;
}
Run Code Online (Sandbox Code Playgroud)
只有一个变化;但是程序无法工作,它就像无限循环一样.
以下是另一个问题:函数mini_path的框架是这样的
int maze::mini_path(){
ini();
queue<pair<int,int> > q;
q.push(make_pair(x,y));
while(!q.empty()){
pair<int,int> tmp=q.front();
q.pop();
int t=...;
if(E){
return t;
}
if(E){
S
}
if(E){
S
}
if(E){
S
}
if(E){
S
}
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)
如果最后有"return -1",则该函数正常工作,否则函数返回随机大数.
该程序只在一个文件中,我使用枪编译器.
我没有显示总代码,因为我认为没有人想看到它们.我只是想问一下哪些问题可能导致奇怪的行为.
源代码(问题2简化):
typedef enum {LEFT=-1,RIGHT=1,UP,DOWN} direction;
ifstream fin("file_test3.txt");
class maze{
public:
maze(){input();}
int mini_path();
void input();
void display(){ …Run Code Online (Sandbox Code Playgroud) 我做了这个:
if( tal[i+1] ){
if( tal[i] == tal[i+1]){
match=true;
}
}
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.
我想在数组tal []中检查当前(i)旁边的字段是否存在.
我怎样才能解决这个问题?
我有一个NSString对象,它被分配给它(" http://vspimages.vsp.virginia.gov/images/024937-02.jpg ").任何人都可以告诉我如何检查字符串是否以".jpg"结尾?
我正在开发一个微调器这个微调器我是字符串数组
spinner = (Spinner)this.findViewById(R.id.mlg);
final CharSequence[] itemArray =getResources().getTextArray(R.array.RectBeam);
final List<CharSequence> itemList =new ArrayList<CharSequence>(Arrays.asList(itemArray));
adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,itemList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Toast.makeText(parent.getContext(), "The planet is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
............................
<string-array name="RectBeam">
<item value="3000000" > Steel</item></string-array>
Run Code Online (Sandbox Code Playgroud)
这是微调器相关的字符串数组我得到的微调器项目我正在使用parent.getItemAtPosition(pos).toString(),完成我的问题是特定的项值如何获得
example : steel----------->3000000
Run Code Online (Sandbox Code Playgroud) 以下是导致问题的序列:
我很困惑:
请赐教:)
谢谢 !
我正在设置一个持续集成作业,该作业修补外部库并在本地发布修补版本.
但是,外部库使用TRUNK进行开发,我希望我的CI作业自动选择最新的发布标签进行结帐.
SVN有这个功能吗?
(bash Shell Scripts可以)
我有一个具有按钮的表单,在按钮单击事件上,变量locklogin增加1
当locklogin = 3时,表单按钮被禁用,表单需要关闭.在关闭表单时,locklogin失去了它的价值.
但我希望保持其价值,虽然表格被关闭,当表格再次运行(整个应用程序再次执行),然后按钮仍然被禁用.我该怎么做呢?
public partial class Form1 : Form
{
static int loginlocked;
static int isloginlocked;
public Form1()
{
InitializeComponent();
if (isloginlocked == 3)
{
foreach (Control c in this.Controls)
{ c.Enabled = false; }
}
}
private void button1_Click(object sender, EventArgs e)
{
loginlocked++;
if (loginlocked == 3)
{
foreach (Control c in this.Controls)
{ c.Enabled = false; }
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
isloginlocked = loginlocked;
if (e.CloseReason …Run Code Online (Sandbox Code Playgroud) 我是JSONP开发的新手,我发现IE 7/8不会清理JSONP脚本占用的内存.运行几个小时后,这会在我的页面中导致非常高的内存消耗.
我浏览了互联网,发现大多数修复都是基于Neil Fraser的提示.从博客中可以看出,您需要使用类似的代码删除脚本中的所有属性
var tmp;
while (tmp = document.getElementById('JSONP')) {
tmp.parentNode.removeChild(tmp);
// this deletion will create error in IE.
for (var prop in tmp) delete tmp[prop];
tmp = null;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,删除将在IE中创建"对象不支持此操作"的错误,并且它不会释放内存.
所以我的问题是如何真正释放我的JSONP脚本的内存?
我把我的测试代码如下:
Testing.html
<html><head></head><body><script>
var script,
head = document.getElementsByTagName('head')[0],
loadCount= 0,
uuid= 1,
URL= "memleaktest.js?uuid=",
clearConsole = function() {
var con= document.getElementById("console");
while (con.childNodes.length)
con.removeChild(con.childNodes[0]);
},
log = function(msg) {
var div= document.createElement("DIV"),
text= document.createTextNode(msg),
con= document.getElementById("console");
div.appendChild(text);
con.appendChild(div);
},
test = { "msg" : null, …Run Code Online (Sandbox Code Playgroud) 是否有可能将"1.hour"字符串转换为1.hour,将"2.hours"转换为2.hours in ruby?实际上我从表格的下拉列表中获取此值.我希望Time.now通过这样的方式添加它
time = Time.now + get_method(params[:hours_or_days])
Run Code Online (Sandbox Code Playgroud)
其中params[:days_or_hours]可能是"2.hours"或"1.hour"或"1.day".我想获得这些字符串的方法转换.可能吗?(通过某些方法send)