Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. /* This is the first program exercise where the spec isn't entirely * clear. The spec says…
首先,要求找到最长最短字符串,我们应该用数组将其存起来,输入的个数是不固定的,我们就可以用Scanner获取要输入的个数,最终找到的个数也不固定,我们可以封装两个方法,并且返回值类型为数组. 我遇到的问题,开始我想到的是字符串拼接,么想到返回值用数组存,导致每次返回的个数都是固定的,就算有多个. 代码如下: import java.util.Scanner; //输入n行字符串,找出最长最短字符串(若有个数相同的,都打印出来) public class FindString { public s…
编程中常常会用到连续多行输入的情况,如果事先知道要输入多少行的话,可以直接定义一个变量,然后用循环就可以实现了,但有时候事先并不知道,要输入多少行,于是就可以用到输入流碰到文件终止符的情况了,具体的操作就是ctrl+Z,然后按下回车键 程序例1 #include<iostream> #include<string> #include<vector> using namespace std; int main() { int num; vector <int&g…