王道机考系列——哈希的应用与排版问题
哈希的应用与排版问题
Hash的应用
-
统计某个成绩的学生的人数;
-
给定n个整数,输出前m大的数
使用桶排序的思路来做。
排版题
1. 梯形排版
输入一个数h,输出一个上底为h,高为h的梯形。
如:
3
***
*****
*******
#include <iostream>
using namespace std;
int main() {
int n;
int space = 0;
int out = 0;
while(scanf("%d", &n) != EOF) {
for(int i = 1; i <= n; i++) {
space = (n - i) * 2;
out = n + (i - 1) * 2;
while(space--)
cout << " ";
while(out--)
cout << "*";