我正在编写一个Sudoku拼图生成器,但是当我编译并运行程序时,我看到的只是一个空白的控制台终端.我一直在等待1小时,但它仍然是一个空白的控制台终端.我想知道它是否因为任何逻辑错误或因为它仍在处理.只是抬头,我的整个代码超长.如果出现性能问题,我该如何优化它
谢谢
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
using namespace std;
bool checkrow(int row,int value,int array[][9]);
void producearray(int array[][9]);
bool checksquare(int row,int col,int value,int array[][9]);
bool checkcol(int col,int value,int array[][9]);
void populatearray(int array[][9]);
void printarray(int array[][9]);
int main()
{
int array[9][9];
populatearray( array);
producearray(array);
printarray(array);
system("PAUSE");
}
bool checkrow(int row,int value,int array[][9])// checks the entire row, returns false if any two numbers in the row are the same
{
for (int j=0;j<9;j++)
{
if (value==array[row][j])
{
return false; …Run Code Online (Sandbox Code Playgroud) For i=0 to 100000
MsgBox("Whats up")
Next i
Run Code Online (Sandbox Code Playgroud)
我试图测试我的FOR循环是否有效,现在我无法停止程序的执行.中断按钮不起作用,我只能按OK.我需要帮助
谢谢
我使用Ajax将我的服务器端代码PHP中的一些数据发回给我的客户端,这就是它的完成方式
//server side
$json="{
"payout_history":"0",
"round_shares":"1816",
"workers":
{
"jbo.5970":
{
"alive":"1",
"hashrate":"1253"
},
"jbo.5970cpu":
{
"alive":"1",
"hashrate":"21"
},
"jbo.5970-2":
{
"alive":"1",
"hashrate":"1062"
}
}
}";
echo json_encode($json);
Run Code Online (Sandbox Code Playgroud)
我在firebug的响应页面中收到此错误,我无法弄清楚它是什么问题
<br />
<b>Parse error</b>: syntax error, unexpected 'payout_history' (T_STRING) in
<b>C:\xampp\htdocs\exercise5json\display.php</b> on line <b>38</b><br />
Run Code Online (Sandbox Code Playgroud) 这是我的代码的一个愚蠢的版本,基本上我试图将STL SET作为函数参数传递,但我无法这样做.我收到以下错误
错误:无法将'std :: set,std :: allocator转换为'int',争论'1'为void foo(int)
错误:模板争论1无效
错误:模板争论2无效
错误:模板争论3无效
这是错误源自的代码示例
#include <iostream>
#include <set>
using namespace std;
void foo(set<foobar>);
class foobar
{
public:
int x;
};
int main()
{
set<foobar> foobar_set;
foo(foobar_set);
}
void foo(set<foobar> foobar_set)
{
}
Run Code Online (Sandbox Code Playgroud)
问题:如何将STL集作为函数参数传递?
STL集存在多长时间,本地范围或全局范围?
当我意识到不可能使用一套装置而我必须创建一个新装置并拥有一个自定义排序功能来诉诸它时,我试图求助于一套.我在网上研究并试图实现我自己的自定义排序功能,但我不知道如何去做
这是我的班级
class Point2D
{
public:
int getX() const;
int getY() const;
void setX(int);
void setY(int);
bool operator < ( const Point2D& x2) const
{
if ( x != x2.x)
{
return x < x2.x;
}
if ( y != x2.y)
{
return y < x2.y;
}
};
protected:
int x;
int y;
};
Run Code Online (Sandbox Code Playgroud)
目前它是根据x值后跟y值排序,我想根据它来求助它
y值后跟x值
因此我实现了这种自定义排序
bool p2d_sortby_y(Point2D& ptd1 , Point2D& ptd2) //custom sort function
{
if ( ptd1.getY() != ptd2.getY())
{
return ptd1.getY() < …Run Code Online (Sandbox Code Playgroud) 我有一个文本文件admin.dat,如下所示:
blackranger|sdasdasdasd23123|1000
blueranger|sdasdasdasdwhhh22|1000
brownranger|lppsadospd123|1000
Run Code Online (Sandbox Code Playgroud)
我试图读取每一行,使用|作为我的分隔符并输出到每个部分的控制台.
代码:
package testing;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Testing {
public static void main(String[] args) {
Scanner filereader = null;
try {
filereader = new Scanner(new File("./src/testing/players.dat"));
String data;
while(filereader.hasNextLine()) {
String foo = "abc|123|a213";
String[] bar = foo.split("|");
for (int i = 0; i < 3; i++) {
System.out.println(bar[i]);
}
}
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试写入文件
try
{
PrintWriter fileout = new PrintWriter("./src/javaapplication1/test.dat");
for(int i=0;i<10;i++)
{
fileout.println(i);
}
}
catch (IOException e)
{
System.out.println("File cannot be created");
}
Run Code Online (Sandbox Code Playgroud)
但是,我期待没有任何内容写入文件
1
2
3
4
5
6
7
8
9
Run Code Online (Sandbox Code Playgroud)
我写这个文件的方式有什么问题?
我正在运行一个非常简单的多线程程序
主程序
package javathread;
public class JavaThread {
public static void main(String[] args)
{
JThread t1 = new JThread(10,1);
JThread t2 = new JThread(10,2);
t1.run();
t2.run();
}
}
Run Code Online (Sandbox Code Playgroud)
JThread.java
package javathread;
import java.util.Random;
public class JThread implements Runnable
{
JThread(int limit , int threadno)
{
t = new Thread();
this.limit = limit;
this.threadno = threadno;
}
public void run()
{
Random generator = new Random();
for (int i=0;i<this.limit;i++)
{
int num = generator.nextInt();
System.out.println("Thread " + threadno + " : …Run Code Online (Sandbox Code Playgroud) 我有一个JLabel PlayerLabel数组和PlayerName数组,它是以下列方式初始化的
String [] PlayerName;
PlayerName = new String[4];
for (int i=0;i<4;i++)
{
PlayerName[i] = "None1";
}
JLabel [] PlayerLabel;
PlayerLabel = new JLabel[4];
for (int i=0;i<4;i++)
{
String num = Integer.toString(i);
String output = "Player " + num + " : " + PlayerName;
PlayerLabel[i] = new JLabel(output);
PlayerLabel[i].setForeground(Color.white);
}
Run Code Online (Sandbox Code Playgroud)
我希望我的JLabel的文本是
玩家1:无1
相反,我得到了
玩家1:java.lang.String; @ 4e9fd887
@15150ef8每次重新启动程序时,部件都会更改为不同的数字和字母组合.
当我初始化时,PlayerName没问题

我不知道为什么在输出时添加PlayerName会变得怪异

发生了什么,我该如何解决这个问题?
这是我的班级 employeeException
#include <iostream>
#include <string>
using namespace std;
class employeeException
{
public:
employeeException(string);
void printmessage();
private:
string message;
};
int main()
{
employeeException("Heelo");
}
employeeException::employeeException(string message)
{
this->message = message;
}
void employeeException:printmessage()
{
cout<<endl
<<this->message
<<endl;
}
Run Code Online (Sandbox Code Playgroud)
由于某些未知原因,我在编译期间遇到此错误
函数定义不声明参数
我无法弄清楚这个简单程序有什么问题.当然,我错过了一些简单的事情.
这是我的代码,我不明白为什么我得到运行时检查失败#2 - 变量'tempSign'周围的堆栈已损坏.我相信错误来自尝试在char*tempSign [MAX]中交换2个值.有人可以解释为什么我得到这个错误,并帮助我解决这个问题谢谢.
void constructSet(ZodiacSign *& z,int size)
{
/*ZodiacSign is a char *
This is how z was created from the previous function and
passed by reference
ZodiacSign * z;
z=new char* [num];
for (int i=0;i<num;i++)
{
z[i]=new char [MAXSTR];
} */
ZodiacSign tempSign [MAX]={"aquarius","pisces","aries","taurus","gemini","cancer","leo",
"vergo","libra","scorpio","sagittarius","capricorn"};
for (int i=0; i<size;i++)
{
int x=12;
int num=(rand()%x);
char * ptr=tempSign[num];
strcpy(z[i],ptr);
swap(num,x,tempSign);
x--;
}
}
void swap(int num,int x,ZodiacSign tempSign [MAX])
{
ZodiacSign temp;
temp=tempSign[num];
tempSign[num]=tempSign[x-1];
tempSign[x]=temp;
}
Run Code Online (Sandbox Code Playgroud)