Ubuntu14.04 给定一个文本,统计其中单词出现的次数 方法1 # solution 1 grep与awk配合使用,写成一个sh脚本 fre.sh sh fre.sh wordfretest.txt #! /bin/bash# solution 1 ] then echo "Usage:$0 args error" exit fi ] then echo "analyse the first file $1" fi #get the first file fi
Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging. 统计输入中单词的长度,并且绘制相应的直方图.水平的直方图比较容易绘制,垂直的直方图较困难一些. /* This program was the
//统计数组中出现次数超过一半的数字 #include <stdio.h> int Find(int *arr, int len) { int num = 0; //当前数字 int times = 0; //当前数字出现的次数 int i = 0; for (i = 0; i<len; i++) { if (times == 0) { num = arr[i]; times = 1; } else if (arr[i] == num) times++; else times--; }