第1个回答 2009-01-09
分数当然越多越好了
程序运行结果:
名次 产品数量 职工人数 职工号
1 375 3 10 20 21
4 250 2 3 5
6 200 1 9
7 150 2 11 14
请按任意键继续. . .
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct emp
{
int no;
int amount;
};
int grater(emp &s1,emp &s2){return s1.amount>s2.amount;}
int main()
{
fstream fin("employee.txt",ios::in);
vector<emp>e(30);
int a,b;
while(fin>>a>>b)
{
e[a].amount+=b;
e[a].no=a;
}
vector<int>::size_type i,j,k;
sort(e.begin(),e.end(),grater);
cout<<"名次\t产品数量\t职工人数\t职工号\n";
for(i=0;i<e.size()&&e[i].amount!=0;i++)
{
int cnt=1;
k=i;
while((i+1)<e.size())
{
if(e[i].amount==e[i+1].amount)
{
i++;
cnt++;
}
else break;
}
cout<<k+1<<"\t "<<e[i].amount<<"\t\t"<<cnt<<"\t\t";
for(j=k;j<=i;j++)
cout<<e[j].no<<" ";
cout<<endl;
}
fin.close();
return 0;
}
第2个回答 2009-01-09
这个是一道程序员考试题 我参加这个考试 电脑上保存了
我这里有原题的答案 ,给多少分啊 哈 我要1000分,给吗?
先给你一半的程序吧
程序}
#include<stdio.h>
typedef struct ele {
int no,q ;
struct ele * next ;
} elem ;
main( int argc, char * * argv)
{ FILE *fp; elem *h, *u, *proc() ;
if ( argc == 2 && ( fp = fopen( argv[1],"r" )) !=NULL )
{ h = proc(fp) ;
fclose (fp) ;
output(h)
while (h I=NULL) { u=h→*next ;free(h) ; h=u ;)
}
}
elem * proc( FILE *fp )
{ intn, m; elem *u, *v, *p, *base ;
base = NULL ;
fscanf( fp, "%d', &m ) ;
while ( ! feof(fp) )
{ fscanf( fp, '%d', &m ) ;
for ( v = base ;v !=NULL && v→no != n ;u = v, v = v→next ) ;
另一半:
if (__①__)
if (__②__) base=v→next ;
else u→next = v - next ;
v→q + - m ;
else v = ( elem * ) malloc( sizeof( elem )) ;
v→no = n ;
v→q = m ;p = base ;
while ( p != NULL )
if (__③__ )break ;
else { u = p ;p = p→next ;}
if ( __④__ ) base = v ;else u→next = v ;
__⑤__ ;
fscanf( fp, "%d",&n ) ;
}
return base ;
}
output( elem * head )
{ int count,order;elem *u, *v ;
printf( "ORDER QUANTITY COUNT NUMBER\n" ) ;
u = head;order = 1 ;
while ( u != NULL )
{ for ( count = 1,v = u→next;__⑥__ ;count++ ,v=v→next );
printf( "%4d%9d%6d",order,u→q,count );
order += count;
for(; __⑦__ ;printf( "%4d",u→no),u=u→next); ·
printf( "\n");
}
}
第3个回答 2009-01-11
又是这个问题,晕!
include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct emp
{
int no;
int amount;
};
int grater(emp &s1,emp &s2){return s1.amount>s2.amount;}
int main()
{
fstream fin("employee.txt",ios::in);
vector<emp>e(30);
int a,b;
while(fin>>a>>b)
{
e[a].amount+=b;
e[a].no=a;
}
vector<int>::size_type i,j,k;
sort(e.begin(),e.end(),grater);
cout<<"名次\t产品数量\t职工人数\t职工号\n";
for(i=0;i<e.size()&&e[i].amount!=0;i++)
{
int cnt=1;
k=i;
while((i+1)<e.size())
{
if(e[i].amount==e[i+1].amount)
{
i++;
cnt++;
}
else break;
}
cout<<k+1<<"\t "<<e[i].amount<<"\t\t"<<cnt<<"\t\t";
for(j=k;j<=i;j++)
cout<<e[j].no<<" ";
cout<<endl;
}
fin.close();
return 0;
}
仔细看看吧
(我从网上下载的,有没有100分呀?)
第4个回答 2009-01-09
我也有答案,我不要1000分。
第5个回答 2009-01-09
高手如云,我连题目也看不懂,真不知道我当初c++是怎么考过的