小编Pan*_*aha的帖子

如何读取BufferedInputStream中的一行?

我正在编写一个代码来使用BufferedInputStream来读取用户的输入,但是当BufferedInputStream读取字节时,我的程序只读取第一个字节并打印它.有没有什么方法可以读取/存储/打印整个输入(这将是整数)除了只读取第一个字节?

import java.util.*;
import java.io.*;
class EnormousInputTest{

public static void main(String[] args)throws IOException {
        BufferedInputStream bf = new BufferedInputStream(System.in)   ;
    try{
            char c = (char)bf.read();

        System.out.println(c);
    }
finally{
        bf.close();
}   
}   
}
Run Code Online (Sandbox Code Playgroud)

输出:

[shadow @ localhost codechef] $ java EnormousInputTest 5452 5

java user-input input bufferedinputstream

17
推荐指数
1
解决办法
2万
查看次数

LinkedList:Collections.max() 抛出 NoSuchElementException

我没有LinkedList通过任何方式(如扫描仪或其他方法)迭代,我使用的Collections.max()是从LinkedList.

我在 Stack Overflow 上读到过这个异常是由于迭代器、扫描器或标记器而引发的,但我没有使用它们。

import java.io.*;
import java.util.*;

class TLG {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        LinkedList<Integer> first = new LinkedList<Integer>();
        LinkedList<Integer> second = new LinkedList<Integer>();

        int cases = Integer.parseInt(br.readLine());

        for(int i=1;i<=cases;i++) {
            String score = br.readLine();
            int number1 = Integer.parseInt(score.split(" ")[0]); 
            int number2 = Integer.parseInt(score.split(" ")[1]); 
            int diff = number1 - number2;

            if(diff > 0){
                first.add(diff);    
            }
            else {
                second.add(java.lang.Math.abs(diff));    
            }
        }

        Integer max1 …
Run Code Online (Sandbox Code Playgroud)

java collections nosuchelementexception

7
推荐指数
2
解决办法
7541
查看次数

如何使用 Pytesseract 提取图像中的小数

要提取的图像

上面是图片,我已经尝试了从 SO 或谷歌可以得到的一切,似乎没有任何效果。我无法获得图像中的确切值,我应该得到 2.10,但它总是得到 210。

并且不限于此图像,任何在数字 1 超正方体之前有小数的图像都会忽略小数值。

 def returnAllowedAmount(self,imgpath):
        th = 127
        max_val = 255
        img = cv2.imread(imgpath,0) #Load Image in Memory
        img = cv2.resize(img, None, fx=2.5, fy=2.5, interpolation=cv2.INTER_CUBIC) #rescale Image
        img = cv2.medianBlur(img, 1)
        ret , img = cv2.threshold(img,th,max_val,cv2.THRESH_TOZERO)
        self.showImage(img)

        returnData = pytesseract.image_to_string(img,lang='eng',config='-psm 13 ' )
        returnData = ''.join(p for p in returnData if p.isnumeric() or p == ".") # REMOVE $ SIGN
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing computer-vision python-tesseract

4
推荐指数
1
解决办法
2347
查看次数

如何从 BeautifulSoup ( Python ) 中的表中获取第一个子表行

这是代码和示例结果,我只希望表格的第一列忽略其余部分。Stackoverflow 上有类似的问题,但没有帮助。

<tr>
<td>JOHNSON</td>
<td> 2,014,470 </td>
<td>0.81</td>
<td>2</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

我只想要 JOHNSON,因为它是第一个孩子。我的python代码是:

import requests
  from bs4 import BeautifulSoup
 def find_raw():
      url = 'http://names.mongabay.com/most_common_surnames.htm'
      r = requests.get(url)
      html = r.content
      soup = BeautifulSoup(html)
      for n in soup.find_all('tr'):
          print n.text
  
  find_raw()
Run Code Online (Sandbox Code Playgroud)

我得到的:

SMITH 2,501,922 1.0061
JOHNSON 2,014,470 0.812
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup python-requests

3
推荐指数
1
解决办法
5867
查看次数