该字符串是在网页表格中复制的,所以数字间由制表符间隔,先将其转换成列表,再进行统计计算.代码如下: str = "-18.1 -18.3 -18 -18.2 -18 -17.4 -18 -18.3 -18 -18 -17.6 -17.2" list = str.split("\t") m = 0.0 for w in list: n = float(w) m += n avg = m/len(list) print("\n列表为:",list)
题目描写叙述: Write a function to find the longest common prefix string amongst an array of strings.就是给定1个字符串数组,找出公共最长前缀. 思路非常直接.使用1个索引来存最长公共前缀的长度就能够了. 注意, 假设使用1个字符串变量来存前缀的话,是不能AC的,由于题目不同意使用额外的空间. public string LongestCommonPrefix(string[] strs) { if(strs
求平均成绩 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58415 Accepted Submission(s): 13985 Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. Inpu
后缀数组的一些基本概念请自行百度,简单来说后缀数组就是一个字符串所有后缀大小排序后的一个集合,然后我们根据后缀数组的一些性质就可以实现各种需求. public class MySuffixArrayTest { public char[] suffix;//原始字符串 public int n;//字符串长度 public int[] rank;// Suffix[i]在所有后缀中的排名 public int[] sa;// 满足Suffix[SA[1]] < Suffix[SA[2]] --