您的位置:首页 > 其它

原 poj 2715(基础题) 奖学金

2012-04-10 09:10 197 查看
注意输出

练习sort 与 scanf

scanf会读入空格字符!!

#include <fstream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;

#define _cdebbug
//全局数据

struct scholar{
char stuname[30] ;
int  qimo ;
int  pingyi ;
int  essays ;
char isganbu ;
char iswest ;
int  money ;
};
bool cmp(const scholar &a,const scholar &b)
{

return a.money < b.money;

}

int main()
{
//重定向
#ifdef _cdebbug
freopen("F:\\input.txt","r",stdin );
#endif

int n;
int i,j ;
int totalschalor = 0 ;
scholar *pstu ;
scanf("%d",&n) ;
pstu = new scholar
;
for (i = 0 ; i < n ; ++i)
{
scanf("%s",pstu[i].stuname) ;
scanf("%d",&pstu[i].qimo) ;
scanf("%d",&pstu[i].pingyi) ;
scanf(" %c",&pstu[i].isganbu) ;
scanf(" %c",&pstu[i].iswest) ;
scanf("%d",&pstu[i].essays) ;
pstu[i].money = 0;
}

for (i = 0 ; i < n ; ++i)
{
//院士
if ( (pstu[i].qimo>80) && (pstu[i].essays>=1) )
pstu[i].money += 8000 ;
if ( (pstu[i].qimo>85) && (pstu[i].pingyi>80))
pstu[i].money += 4000 ;
if (pstu[i].qimo > 90)
pstu[i].money += 2000 ;
if ( (pstu[i].qimo>85)&&(pstu[i].iswest=='Y'))
pstu[i].money += 1000 ;
if ((pstu[i].pingyi>80)&&(pstu[i].isganbu=='Y'))
pstu[i].money += 850 ;
totalschalor += pstu[i].money ;
}

stable_sort(pstu,pstu+n,cmp) ;
int maxm = pstu[n-1].money ;

for (i = 0 ; i < n ; ++i)
{
if (pstu[i].money == maxm)
{
printf("%s\n",pstu[i].stuname) ;
printf("%d\n",pstu[i].money)   ;
break;
}
}

printf("%d\n",totalschalor)      ;

//解除重定向关闭文件

#ifdef _cdebbug
fclose(stdin);
#endif
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: