接收一个c + +矩阵并在java中放入一个矩阵 [英] receive an matrix of c + + and put in a matrix in java

查看:66
本文介绍了接收一个c + +矩阵并在java中放入一个矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

 

我想知道如何在Java控制台的矩阵中放置一个来自c + +代码的矩阵java的。实际上,我从java代码向我的c ++代码发送参数,收入的收入是以文本的形式在java控制台上。所以,我想从文本中提取矩阵。我需要稍后在代码中,老实说我不知道​​如何。

 

下面,这是我的java代码

hi everyone!
 
I would like to know how you can put a matrix that came from c + + code in the Java console in an matrix in java. In fact, I send parameter to my c + + code from the java code, and the receipt of income is at the java console in the form of a text. so, I want to extract the matrix from the text .I need later in the code, I honestly do not know how.
 
below, this is my java code

OutputStream out = null;
     OutputStream err = null;
     PipedInputStream pipedInput = new PipedInputStream();
     PipedOutputStream pipedOutput = new PipedOutputStream(pipedInput);
     Program prog = new Program("C:\\Users\\abdelhalim\\Desktop\\ExempleMMKP33.exe", System.out, System.err, pipedInput);
        // TODO: Write pipedOutput from your favorite thread to send input to the program and finally close the stream.
        // I will use a PrintWriter because we are working here with text and not binary data.
        PrintWriter pw = new PrintWriter(pipedOutput);
        // println outputs platform specific newline but pw.print("5\n" ) would also convert "\n" to platform specific newline.
      
      
       res1= new int[n][m];
        pw.println(m);
        pw.println(n);
        pw.println(m);
        pw.println(n);
      
        for(int k=0; k<R.size();k++)
        { 
        pw.println(R.get(k));
        }
      
        for(int k=0; k<C.size();k++)
        {
       
        pw.println(C.get(k));
        }
        for(int k=0; k<B.size();k++)
        {
       
        pw.println(B.get(k));
        }
        for(int k=0; k<Dr.size();k++)
        {
       
        pw.println(Dr.get(k));
        }
        for(int k=0; k<Dc.size();k++)
        {
       
        pw.println(Dc.get(k));
        }
        for(int k=0; k<Db.size();k++)
        {
       
        pw.println(Db.get(k));
        }
        /*for(int k=0; k<n;k++)
        {
      for(int j=0; j<m;j++)
 	    pw.println(GainMatrix[k][j]);
 	   }*/
        pw.println(n);
        pw.println(m);
        pw.println(m);
        pw.println(m);
pw.close();





这是我在java控制台中获得的:





and this is what I get in the java console:

0   0   0   0   1   0
   0   0   0   0   0   1
   0   1   0   0   0   0
   0   0   0   1   0   0
   0   0   0   0   1   0
   0   0   1   0   0   0
Initial
propagators: 24
branchers:   1
Summary
runtime:      1.735 (1735.000 ms)
solutions:    48
propagations: 1715
nodes:        153
failures:     29
restarts:     0
peak depth:   7
peak memory:  13 KB





我想把这个矩阵放在java代码矩阵中(矩阵类型res1 =新的int [n] [m])接待后,我不知道该怎么办?? ,,

 

你对此有所了解吗? ?非常感谢你的帮助



I want to put this matrix in a java code matrix (matrix type res1 = new int [n] [m]) after the reception and I do not know how to do it ??,,
 
you have an idea about that?? thank you very much for your help

推荐答案

将控制台输出作为字符串读取并扫描。空格表示整数结束,新行表示新行。你扫描字符串两次:首先运行以检测尺寸,然后再运行以读取值。



非常重要:实现强大的错误处理!!!
Read the console output as string and scan it. A space means end of integer, a new line a new row. You scans the string twice: first run to detect the dimensions and second run to read the values.

Very important: Implement robust error handling!!!


这篇关于接收一个c + +矩阵并在java中放入一个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆