由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教一个C++的编程
相关主题
Question about a TICPP example请教一个作用域的问题
谁给新手解释一下这个c++小程序[合集] C++问题(copy constructor)
a simple question for C++ classWhy should i include .cpp instead of .h
关于 VC++ vitual, reload 和 derive的一个问题...prevent assignment
发个初级面试题C++弱问
最初级的白痴C++问题问一个简单的C++问题
C++里面C++菜问: 怎么这样也可以?
C++疑问C++ 初学者请教一个 iostream 的问题
相关话题的讨论汇总
话题: listnode话题: int话题: count话题: c++话题: include
进入Programming版参与讨论
1 (共1页)
s****h
发帖数: 1329
1
代朋友请教:
任意输入一组整数(数字可以重复), 得出的结果是两个columns(不需要有表格), 一个
列出出现过的整数(重复的数列出一个就可以了),并且从大到小排列, 另一个列出相对
应的数出现的次数. 排列没有问题, 怎样用two-dimension array做出每个数出现的次数?
比如:
3 6 5 -2 6 3 2
output:
N Count
6 2
5 1
3 2
2 1
-2 1
S*****n
发帖数: 227
2
这个题好象没有任何难度啊。

次数?

【在 s****h 的大作中提到】
: 代朋友请教:
: 任意输入一组整数(数字可以重复), 得出的结果是两个columns(不需要有表格), 一个
: 列出出现过的整数(重复的数列出一个就可以了),并且从大到小排列, 另一个列出相对
: 应的数出现的次数. 排列没有问题, 怎样用two-dimension array做出每个数出现的次数?
: 比如:
: 3 6 5 -2 6 3 2
: output:
: N Count
: 6 2
: 5 1

P********e
发帖数: 2610
3
靠,这个是我TA课的作业啊,我才教大一生啊
可能你题目表达不清楚吧

次数?

【在 s****h 的大作中提到】
: 代朋友请教:
: 任意输入一组整数(数字可以重复), 得出的结果是两个columns(不需要有表格), 一个
: 列出出现过的整数(重复的数列出一个就可以了),并且从大到小排列, 另一个列出相对
: 应的数出现的次数. 排列没有问题, 怎样用two-dimension array做出每个数出现的次数?
: 比如:
: 3 6 5 -2 6 3 2
: output:
: N Count
: 6 2
: 5 1

e*a
发帖数: 32
4
说不定就是你班上的

【在 P********e 的大作中提到】
: 靠,这个是我TA课的作业啊,我才教大一生啊
: 可能你题目表达不清楚吧
:
: 次数?

k****f
发帖数: 3794
5
哈哈,那就巧了

【在 e*a 的大作中提到】
: 说不定就是你班上的
P********e
发帖数: 2610
6
我们是JAVA的

【在 k****f 的大作中提到】
: 哈哈,那就巧了
s****h
发帖数: 1329
7
hehe...是一个自学c++的朋友的,因为是自己看书(这题是书上的)有问题只好问朋友.可
我不写程序好几年了,脑子里早就被别的东西塞满了,现在忙得自己的事儿都顾不上,实
在没功夫帮别人想这个.
你给学生布置作业就直接用书上的呀?偷懒啊...我记得我们那时程序题都是老师自己想
出来的,让我们没处考古去....
高手们支个招诲人不倦一下吧,大概思路就行.

【在 P********e 的大作中提到】
: 靠,这个是我TA课的作业啊,我才教大一生啊
: 可能你题目表达不清楚吧
:
: 次数?

y*******g
发帖数: 6599
8
直接暴力查找 然后出现次数+1

【在 s****h 的大作中提到】
: hehe...是一个自学c++的朋友的,因为是自己看书(这题是书上的)有问题只好问朋友.可
: 我不写程序好几年了,脑子里早就被别的东西塞满了,现在忙得自己的事儿都顾不上,实
: 在没功夫帮别人想这个.
: 你给学生布置作业就直接用书上的呀?偷懒啊...我记得我们那时程序题都是老师自己想
: 出来的,让我们没处考古去....
: 高手们支个招诲人不倦一下吧,大概思路就行.

S*****n
发帖数: 227
9
这还要什么思路啊?所有数字都读进来,然后排序啊(或者边读边插入排序)。排成
1 1 2 2 3 4 5 7 7 9
这样的。
然后就边数边输出呗。

【在 s****h 的大作中提到】
: hehe...是一个自学c++的朋友的,因为是自己看书(这题是书上的)有问题只好问朋友.可
: 我不写程序好几年了,脑子里早就被别的东西塞满了,现在忙得自己的事儿都顾不上,实
: 在没功夫帮别人想这个.
: 你给学生布置作业就直接用书上的呀?偷懒啊...我记得我们那时程序题都是老师自己想
: 出来的,让我们没处考古去....
: 高手们支个招诲人不倦一下吧,大概思路就行.

d*****9
发帖数: 70
10
Maybe failed in testing, be careful, just for practice.
// This program reads a sequence of integers
// Then print their values and count in a two columns number
// Definition of node
#include
#include
using namespace std;
//Declaration:
class listNode;
void insertIntoList(char temp, list nodeList);
class listNode
{
int value;
int count;
public:
listNode(){value =0, count=0;}
listNode(int number);
~listNode();
int getValue() {return value;}
s****u
发帖数: 118
11
#include
#include
using namespace std;
int main() {
int num;
map count;
while (cin >> num) {
count[num]++;
}
for (map::reverse_iterator it(count.rbegin()); it != count.rend(
); ++it) {
cout << it->first << " " << it->second << endl;
}
}

【在 d*****9 的大作中提到】
: Maybe failed in testing, be careful, just for practice.
: // This program reads a sequence of integers
: // Then print their values and count in a two columns number
: // Definition of node
: #include
: #include
: using namespace std;
: //Declaration:
: class listNode;
: void insertIntoList(char temp, list nodeList);

d*****9
发帖数: 70
12
Yeah, this is very convenient!
are you using hash-table?

rend(

【在 s****u 的大作中提到】
: #include
: #include
: using namespace std;
: int main() {
: int num;
: map count;
: while (cin >> num) {
: count[num]++;
: }
: for (map::reverse_iterator it(count.rbegin()); it != count.rend(

k****f
发帖数: 3794
13
stl map,不是hashtable

【在 d*****9 的大作中提到】
: Yeah, this is very convenient!
: are you using hash-table?
:
: rend(

1 (共1页)
进入Programming版参与讨论
相关主题
C++ 初学者请教一个 iostream 的问题发个初级面试题
腆着脸在问一道最初级的白痴C++问题
大家来做题C++。C++里面
小问题C++疑问
Question about a TICPP example请教一个作用域的问题
谁给新手解释一下这个c++小程序[合集] C++问题(copy constructor)
a simple question for C++ classWhy should i include .cpp instead of .h
关于 VC++ vitual, reload 和 derive的一个问题...prevent assignment
相关话题的讨论汇总
话题: listnode话题: int话题: count话题: c++话题: include