HDU

HDOJ 1040:读入数据并排序输出

前提是你 提交于 2020-03-24 08:04:04
3 月,跳不动了?>>> 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1040 一、题目要求 给出若干组数据,对每组数据排序后输出 二、题目代码 #include<iostream> using namespace std; int main() { int array[1001];//存储读入的数据 int counta; //数据组数 int countb; //每组数据的数据个数 int i, j, k; //for语句遍历用变量 int temp; //临时变量 cin >> counta; while(counta--) { cin >> countb; //读取一组数据 for(i = 0; i < countb; i++) { cin >> array[i]; } //对数据进行排序 for(i = 0; i < countb - 1; i++) { for(j = i + 1; j < countb; j++) { if(array[i] > array[j]) { //cout << "change:" << array[i] << ' ' << array[j] << endl; temp = array[i]; array[i] = array[j]; array[j] = temp; } } } /

HDOJ 1004:统计气球数

我的未来我决定 提交于 2020-03-24 08:03:48
3 月,跳不动了?>>> 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1004 一、题目要求 输入:给定一个数字和一组颜色数据,数字是这组颜色数据的数量。当输入的数字为0时结束。 输出:对于每一组给定的颜色数据, 统计其中出现频率最高的颜色。 二、实现思路 用链表统计颜色数,每发现一个新颜色都插入一个新结点。接收完所有数据后,遍历链表可以找出统计数量最多的颜色,该颜色即为所求。 三、程序代码 #include<iostream> using namespace std; //结构:结点 struct Node { string color; //颜色名 int count; //接收到该颜色的数量 Node *next; //下个结点指针 }; int main() { int count; while(cin >> count) { if(count == 0) { break; } string color; //接收输入 Node *head = NULL, *pointer; while(count--) { cin >> color; //首结点为空则插入首结点 if(head == NULL) { head = new Node(); head -> color = color; head -> count = 1;

HDOJ 1062:字符串翻转问题

谁说胖子不能爱 提交于 2020-03-24 08:03:38
3 月,跳不动了?>>> 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1062 一、题目要求 现有若干行输入,每行输入都有若干个字符串,每个字符串中间都间隔了若干个空格 读入这些输入后,将其按原有格式输出(即空格与回车字符位置不变),但每个字符串都要被翻转 二、题目代码 #include<iostream> using namespace std; int main() { int count; //文字行数 int curr; //用于遍历读入的一行文字 string s; //读取的一行文字 string temp; //临时存储一小段连续的不含空格的文字 cin >> count; getchar(); //读取count后面的'\n' while(count--) { getline(cin, s); temp = ""; for(curr = 0; curr < s.length(); curr++) { //读入到最后一个字符,输出最后一个字符串的翻转 if(curr == s.length() - 1 && s[curr] != ' ') { temp = s[curr] + temp; cout << temp; } //读入到空格后,输出上一个字符串的翻转 else if(s[curr] == ' ') {