C++比赛分数编程 大家来看看

C++比赛分数编程 大家来看看,第1张

#include <fstream>

using namespace std;

//下列函数输入一个数组,返回平均成绩,或最高和最低分数

double Statistic(double score, double &max, double &min,double &sum int n)

{

sum = score[0];

max = min = score[0];

for(int i = 1; i < n; ++i)

{

if(score[i] > max) max = score[i];

if(score[i] < min) min = score[i];

sum += a[i];

}

sum -= max + min;

return sum / double(n - 2);

}

int main()

{

const int PW = 7;

const int NM = 5;

string name;

double score[PW];

ifstream fin("f1txt");

if(!fin) exit(1);

ofstream fout("f2txt");

if(!fout) exit(2);

for(int i = 0; i < NM; ++i)

{

fin>>name;

for(int j = 0; j < PW; ++j)

fin>>score[j];

double sum, ave, max, min;

ave = Statistic(score, max, min, sum, PW);

fout<<name<<" "<<max<<""<<min<<" "<<sum<<" "<<ave<<endl;

}

finclose();

foutclose();

return 0;

}

#include<iostream>

#include<string>

#include <algorithm>

#include <cstdlib>

#include<vector>

#include<cstring>

using namespace std;

inline int gcd(unsigned long a,unsigned long b){//最大公约数

if(b==0)return a;

return gcd(b,a%b);

}

inline int lcd(unsigned long a,unsigned long b){//最小公倍数

return abgcd(a,b);

}

class Fraction{

protected:

unsigned long numerator ;//分子

unsigned long denominator;//分母

char flag;//正负号

public:

Fraction(unsigned long n=0,unsigned long d=1,char f='+'){//有参数的构造函数

int temp=gcd(n,d);

if(temp==0)

temp=1;

numerator=n/temp;

denominator=d/temp;//规格化

flag=f;

};

Fraction(const Fraction &b ){//COPY构造函数

numerator=bnumerator;

denominator=bdenominator;

flag=bflag;

};

char getFlag(){return flag;}

Fraction reciprocal ()const{//倒数

return Fraction(this->denominator,this->numerator,this->flag);

}

friend Fraction reciprocal(Fraction &b){//倒数

return Fraction(bdenominator,bnumerator,bflag);

}

bool Correct(){//判断分数形式是否合法、是否是既约分数

if(denominator==0||gcd(denominator,numerator)!=1)

return false;

return true;

}

void Cout(){//格式化输出Fraction

if(flag=='-')

cout<<"-";

printf("%lu/",numerator);

printf("%lu",denominator);

}

const Fraction & operator =( const Fraction b ){//重载=

numerator=bnumerator;

denominator=bdenominator;

flag=bflag;

return this;

}

friend Fraction & operator -( const Fraction &a,const Fraction &b );

friend Fraction & operator +( const Fraction &a,const Fraction &b ){//重载+

Fraction c;

if(aflag!=bflag)

return a-Fraction(bnumerator,bdenominator,aflag);

unsigned long temp=gcd(adenominator,bdenominator);

cdenominator=lcd(bdenominator,adenominator);

cnumerator=anumeratorcdenominator/adenominator+bnumeratorcdenominator/bdenominator;

temp=gcd(cdenominator,cnumerator);

cdenominator/=temp;

cnumerator/=temp;

cflag=aflag;

return c;

}

friend Fraction & operator -( const Fraction &a,const Fraction &b ){//重载-

Fraction c;

if(aflag!=bflag)

return a+Fraction(bnumerator,bdenominator,aflag);

unsigned long temp=gcd(adenominator,bdenominator);

cdenominator=lcd(bdenominator,adenominator);

cnumerator=anumeratorcdenominator/adenominator-bnumeratorcdenominator/bdenominator;

temp=gcd(cdenominator,cnumerator);

cdenominator/=temp;

cnumerator/=temp;

cflag=aflag;

if(cnumerator<0){

cnumerator=0-cnumerator;

if(cflag=='+')

cflag='-';

else cflag='+';

}

return c;

}

friend Fraction & operator ( const Fraction &a,const Fraction &b ){//重载

Fraction c;

cdenominator=adenominatorbdenominator;

cnumerator=anumeratorbnumerator;

unsigned long temp=gcd(cdenominator,cnumerator);

cdenominator/=temp;

cnumerator/=temp;

if(aflag==bflag)

cflag='+';

else cflag='-';

return c;

}

friend Fraction & operator /( const Fraction &a,const Fraction &b ){//重载/

Fraction c(breciprocal());

return ac;

}

friend bool operator==(const Fraction &a,const Fraction &b ){//重载==

return adenominator==bdenominator&&anumerator==bnumerator&&aflag==bflag;

}

};

inline Fraction Fraction_random(){//产生随机分数

return Fraction(rand(),rand()+1,(rand()&1)'-':'+');

}

Fraction fra[10][3];//分别存储随机生成的10个多项式的第一个运算数,第二个运算数,结果

char pol[10];//存储随机产生的10个多项式的运算类型

//举例,如a+b=c,则fra[i][0]=a,fra[i][1]=b,fra[i][2]=c,pol[i]='+'

//题目没有要求构造多项式类,所以这里就这么简化处理了~~

void Polynomial_random(){//生成全部10个随机多项式和其结果

for(int i=0,temp;i<10;i++){

temp=rand()%4;

fra[i][0]=Fraction_random();

fra[i][1]=Fraction_random();

if(temp==0){

pol[i]='+';

fra[i][2]=fra[i][0]+fra[i][1];

}

if(temp==1){

pol[i]='-';

fra[i][2]=fra[i][0]-fra[i][1];

}

if(temp==2){

pol[i]='';

fra[i][2]=fra[i][0]fra[i][1];

}

if(temp==3){

pol[i]='/';

fra[i][2]=fra[i][0]/fra[i][1];

}

}

}

void Cout(){//格式化输出10个多项式

for(int i=0;i<10;i++){

cout<<i+1<<"、\t";

fra[i][0]Cout();

printf(" %c ",pol[i]);

if(fra[i][1]getFlag()=='-'){

cout<<"(";

fra[i][1]Cout();

cout<<")";

}

else fra[i][1]Cout();

cout<<"=\n";

}

}

void Cin(){//读入答案并判断正误,最后统计分数

cout<<"\n";

cout<<" 请顺序输入每题答案: \n";

cout<<" (注意:1、输入的答案必须为既约分数,否则视为错误答案 \n";

cout<<" 2、若答案为0请输入0/1,否则视为错误答案) \n";

cout<<"\n";

string s;

unsigned long a,b;

int pos,score=0;

for(int i=0;i<10;i++){

pos=0;

a=0;

b=0;

cout<<i+1<<"、\t";

cin>>s;

while(s[pos]!='/'&&s[pos])

pos++;

if(s[0]!='-'){

for(int j=pos-1,k=1;j>=0;j--,k=10)

a+=(s[j]-'0')k;

}

else {

for(int j=pos-1,k=1;j>0;j--,k=10)

a+=(s[j]-'0')k;

}

for(int j=ssize()-1,k=1;j>pos;j--,k=10)

b+=(s[j]-'0')k;

if(Fraction(a,b,'+')==fra[i][2]){

cout<<"正确"<<endl;

score+=10;

}

else {

cout<<"错误,正确答案为:\t";

fra[i][2]Cout();

cout<<endl;

}

}

cout<<endl;

cout<<"总分:"<<score<<endl;

}

int main(){

Polynomial_random();

Cout();

Cin();

return 0;

}

#include <stdioh>

#include <stdlibh>

main()

{

    float score, max1=0, max2=0, min1=10, min2=10, sum = 0; // 假设是10分制

    int i, n;

    printf("输入评委的人数: ");

    scanf("%d", &n);

    score = (float )malloc(sizeof(float));

    printf("依次输入%d个评委打出的分数:\n", n);

    for(i = 0; i < n; i++) {

        scanf("%f", score+i);

        sum += score[i];

        if(score[i] > max1) {

            max2 = max1;

            max1 = score[i];

        } else if(score[i] > max2)

            max2 = score[i];

        if(score[i] < min1) {

            min2 = min1;

            min1 = score[i];

        } else if(score[i] < min2)

            min2 = score[i];

    }

    sum -= max1 + min1;

    if(n >= 9) {

        sum -= max2 + min2;

        n -= 4;

    } else n -= 2;

    printf("选手的平均分是: %2f\n", sum/n);

}

楼主你好,你看看下面这个代码吧   和你的比较相似 :

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

class School{

private:

int id;//学校编号

string name;//学校名称

int total;//学校总分

int male;//男子总分

int female;//女子总分

public:

School(){//初始化

id=0;

male=0;

female=0;

total=0;

}

void setName(string s){

name=s;

}

string getName(){

return name;

}

void setId(int i){

id=i;

}

int getId(){

return id;

}

void setTotal(int a){

total=a;

}

int getTotal(){

return total;

}

void setMale(int a){

male=a;

}

void setFemale(int a){

female=a;

}

int getMale(){

return male;

}

int getFemale(){

return female;

}

};

class Item{

private:

School sc[20];

string name;

public:

School getSchool(int i){

return sc[i];

}

School getSchools(){

return sc;

}

void setSchool(School sch,int i){

sc[i]=sch;

}

void setName(string s){

name=s;

}

string getName(){

return name;

}

};

class Count{

private:

School sc[20];

Item item[20];

int integral[5];

int n;

public:

Count(){

n=0;

integral[0]=7;

integral[1]=5;

integral[2]=3;

integral[3]=2;

integral[4]=1;

}

void input();//输入

void print(int);//打印

void statisticsForTotal();//按总分排序

void statisticsForId();//按编号排序

void statisticsForMale();//按男子总分排序

void statisticsForFemale();//按女子总分排序

void schoolInfo();//显示学校信息

void itemInfo();//显示项目信息

void menu();//显示菜单

void sort(School,string,int);//排序 *** 作

};

void Count::input(){

int i,j,num,m,f,id;

School sch;

Item it;

string s;

cout<<"输入学校数目:";

cin>>n;

for(i=0;i<n;i++){

sch=new School;

cout<<"请输入第"<<i+1<<"学校的名称:";

cin>>s;

sch->setName(s);

sch->setId(i+1);

sc[i]=sch;

}

cout<<"输入男子和女子项目的数目:";

cin>>m;

cin>>f;

while(m>20||m<1||f>20||f<1){

cout<<"输入数据有误,请重新输入:"<<endl;

cin>>m;

cin>>f;

}

for(i=0;i<m+f;i++){

cout<<"输入第"<<i+1<<"个项目的名称:";

cin>>s;

it=new Item;

it->setName(s);

item[i]=it;

cout<<"输入第"<<i+1<<"个项目的前5名学校的编号:"<<endl;

for(j=0;j<5;j++){

cin>>id;

if(i<m)

sc[id-1]setMale(sc[id-1]getMale()+integral[j]);

else if(i<m+f)

sc[id-1]setFemale(sc[id-1]getFemale()+integral[j]);

sc[id-1]setTotal(sc[id-1]getTotal()+integral[j]);

item[i]setSchool(sc[id-1],j);

}

}

}

void Count::print(int i){

cout<<"   "<<sc[i]getId()<<setw(10)<<sc[i]getName()<<setw(8)<<sc[i]getTotal()

<<setw(9)<<sc[i]getMale()<<setw(10)<<sc[i]getFemale()<<endl;

}

void Count::sort(School sch,string mode,int num){//排序函数

int i,j,exchange;

School t;

if(mode=="total"){

exchange=0;

for(i=0;i<num-1;i++){

for(j=num-2;j>=0;j--)

if(sch[j+1]getTotal()>sch[j]getTotal()){

exchange=1;

t=sc[j+1];

sch[j+1]=sch[j];

sch[j]=t;

}

if(!exchange)

return;

}

return;

}

if(mode=="id"){

for(i=0;i<num;i++){

for(j=i+1;j<num;j++)

if(sch[i]getId()>sch[j]getId()){

t=sch[i];

sch[i]=sch[j];

sch[j]=t;

}

}

return;

}

if(mode=="male"){

exchange=0;

for(i=0;i<num-1;i++){

for(j=num-2;j>=0;j--)

if(sch[j+1]getMale()>sch[j]getMale()){

exchange=1;

t=sc[j+1];

sch[j+1]=sch[j];

sch[j]=t;

}

if(!exchange)

return;

}

return;

}

if(mode=="female"){

exchange=0;

for(i=0;i<num-1;i++){

for(j=num-2;j>=0;j--)

if(sch[j+1]getFemale()>sch[j]getFemale()){

exchange=1;

t=sc[j+1];

sch[j+1]=sch[j];

sch[j]=t;

}

if(!exchange)

return;

}

return;

}

}

void Count::statisticsForTotal(){

int i;

sort(sc,"total",n);

cout<<"按总分排序:"<<endl;

cout<<"学校编号  学校名称  总分 男子总分 女子总分"<<endl;

for(i=0;i<n;i++)

print(i);

}

void Count::statisticsForId(){

int i;

sort(sc,"id",n);

cout<<"按编号排序为:"<<endl;

cout<<"学校编号 学校名称 总分 男子总分 女子总分"<<endl;

for(i=0;i<n;i++)

print(i);

}

void Count::statisticsForMale(){

int i;

sort(sc,"male",n);

cout<<"按男子项目积分排序:"<<endl;

cout<<"学校编号 学校名称 总分 男子总分 女子总分"<<endl;

for(i=0;i<n;i++)

print(i);

}

void Count::statisticsForFemale(){

int i;

sort(sc,"female",n);

cout<<"按女子项目积分排序:"<<endl;

cout<<"学校编号 学校名称 总分 男子总分 女子总分"<<endl;

for(i=0;i<n;i++)

print(i);

}

void Count::schoolInfo(){ //查询学校的情况

int i,s;

cout<<"输入需要查询的学校编号:";

while(1){

cin>>s;

if(s<1||s>n){

cout<<"输入数据有误,请重新输入:";

continue;

}

break;

}

printf("该学校的信息信息:\n");

printf("编号 学校名称 总分 男子总分 女子总分\n");

for(i=0;i<n;i++){

if(sc[i]getId()==s){

print(i);

break;

}

}

cout<<endl;

}

void Count::itemInfo(){ //查询项目的情况

int i,s;

cout<<"输入需要查询的项目的编号:";

while(1){

cin>>s;

if(s<1||s>n){

cout<<"输入数据有误,请重新输入:";

continue;

}

break;

}

cout<<item[s-1]getName()<<"前5名学校编号及名称为:"<<endl;

sort(item[s-1]getSchools(),"total",5);

cout<<"名次 学校编号 学校名称"<<endl;

for(i=0;i<5;i++)

cout<<" "<<i+1<<"\t"<<item[s-1]getSchool(i)getId()

<<"\t"<<item[s-1]getSchool(i)getName()<<endl;

}

void Count::menu(){ //程序菜单

int i,flag=1;

while(flag){

cout<<"选择您需要的 *** 作:"<<endl;

cout<<"1按学校编号排序输出"<<endl;

cout<<"2按学校总分排序输出"<<endl;

cout<<"3按学校男总分排序输出"<<endl;

cout<<"4按学校女总分排序输出"<<endl;

cout<<"5查询某个学校成绩"<<endl;

cout<<"6查询某个项目成绩"<<endl;

cout<<"7结束"<<endl;

cin>>i;

while(i<1||i>7){

cout<<"你的输入有误,请重新输入:";

cin>>i;

}

switch(i){

case 1:

statisticsForId();

break;

case 2:

statisticsForTotal();

break;

case 3:

statisticsForMale();

break;

case 4:

statisticsForFemale();

break;

case 5:

schoolInfo();

break;

case 6:

itemInfo();

break;

case 7:

flag=0;

break;

}

}

}

void main(){

Count c;

cinput();

cmenu();

}

希望能够帮助到你!

胜一场得2分,输一场得1分,未出场比赛或未完成比赛的 场次为0分

名次计算分两步:

,根据所获得的场次分数多少决定。

2-①,如果有两个或更多的队得分相同,他们有关的名次应按他们相应之间比赛的成绩决定,首先计算他们之间获得的场次分数多少决。

2-②如果还相同,再根据他们相应之间比赛获胜局数和负的局数比率,算出名次。

#include <malloch>

#include <stdioh>

#include <stdlibh>

#include <stringh>

#define NULL 0

#define MaxSize 30

typedef struct athletestruct /运动员/

{

char name[20];

int score; /分数/

int range; //

int item; /项目/

}ATH;

typedef struct schoolstruct /学校/

{

int count; /编号/

int serial; //

int menscore; /男选手分数/

int womenscore; /女选手分数/

int totalscore; /总分/

ATH athlete[MaxSize]; //

struct schoolstruct next;

}SCH;

int nsc,msp,wsp;

int ntsp;

int i,j;

int overgame;

int serial,range;

int n;

SCH head,pfirst,psecond;

int phead=NULL,pafirst=NULL,pasecond=NULL;

input ()

{

char answer;

head = (SCH )malloc(sizeof(SCH)); //

head->next = NULL;

pfirst = head;

answer = 'y';

while ( answer == 'y' )

{

Is_Game_DoMain:

printf("\nGET Top 5 when odd\nGET Top 3 when even");

printf("\n输入运动项目序号 (x<=%d):",ntsp);

scanf("%d",pafirst);

overgame = pafirst;

if ( pafirst != phead )

{

for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )

{

if ( overgame == pasecond )

{

printf("\n这个项目已经存在请选择其他的数字\n");

goto Is_Game_DoMain;

}

}

}

pafirst = pafirst + 1;

if ( overgame > ntsp )

{

printf("\n项目不存在");

printf("\n请重新输入");

goto Is_Game_DoMain;

}

switch ( overgame%2 )

{

case 0: n = 3;break;

case 1: n = 5;break;

}

for ( i = 1 ; i <= n ; i++ )

{

Is_Serial_DoMain:

printf("\n输入序号 of the NO%d (0<x<=%d): ",i,nsc);

scanf("%d",&serial);

if ( serial > nsc )

{

printf("\n超过学校数目,请重新输入");

goto Is_Serial_DoMain;

}

if ( head->next == NULL )

{

create();

}

psecond = head->next ;

while ( psecond != NULL )

{

if ( psecond->serial == serial )

{

pfirst = psecond;

pfirst->count = pfirst->count + 1;

goto Store_Data;

}

else

{

psecond = psecond->next;

}

}

create();

Store_Data:

pfirst->athlete[pfirst->count]item = overgame;

pfirst->athlete[pfirst->count]range = i;

pfirst->serial = serial; ("Input name:) : ");

scanf("%s",pfirst->athlete[pfirst->count]name);

}

printf("\n继续输入运动项目(y&n)?");

answer = getch();

printf("\n");

}

}

calculate() //

{

pfirst = head->next;

while ( pfirst->next != NULL )

{

for (i=1;i<=pfirst->count;i++)

{

if ( pfirst->athlete[i]item % 2 == 0 )

{

switch (pfirst->athlete[i]range)

{

case 1:pfirst->athlete[i]score = 5;break;

case 2:pfirst->athlete[i]score = 3;break;

case 3:pfirst->athlete[i]score = 2;break;

}

}

else

{

switch (pfirst->athlete[i]range)

{

case 1:pfirst->athlete[i]score = 7;break;

case 2:pfirst->athlete[i]score = 5;break;

case 3:pfirst->athlete[i]score = 3;break;

case 4:pfirst->athlete[i]score = 2;break;

case 5:pfirst->athlete[i]score = 1;break;

}

}

if ( pfirst->athlete[i]item <=msp )

{

pfirst->menscore = pfirst->menscore + pfirst->athlete[i]score;

}

else

{

pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i]score;

}

}

pfirst->totalscore = pfirst->menscore + pfirst->womenscore;

pfirst = pfirst->next;

}

}

output()

{

pfirst = head->next;

psecond = head->next;

while ( pfirst->next != NULL )

{

clrscr();

printf("\n第%d号学校的结果成绩:",pfirst->serial);

printf("\n\n项目的数目\t学校的名字\t分数");

for (i=1;i<=ntsp;i++)

{

for (j=1;j<=pfirst->count;j++)

{

if ( pfirst->athlete[j]item == i )

{

printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j]name,pfirst->athlete[j]score);break;

}

}

}

printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");

getch();

pfirst = pfirst->next;

}

clrscr();

printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");

pfirst = head->next;

while ( pfirst->next != NULL )

{

printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);

pfirst = pfirst->next;

}

printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");

getch();

}

create()

{

pfirst = (struct schoolstruct )malloc(sizeof(struct schoolstruct));

pfirst->next = head->next ;

head->next = pfirst ;

pfirst->count = 1;

pfirst->menscore = 0;

pfirst->womenscore = 0;

pfirst->totalscore = 0;

}

void Save()

{FILE fp;

if((fp = fopen("schooldat","wb"))==NULL)

{printf("can't open schooldat\n");

fclose(fp);

return;

}

fwrite(pfirst,sizeof(SCH),10,fp);

fclose(fp);

printf("文件已经成功保存\n");

}

main()

{

system("cls");

printf("\n\t\t\t 运动会分数统计\n");

printf("输入学校数目 (x>= 5):");

scanf("%d",&nsc);

printf("输入男选手的项目(x<=20):");

scanf("%d",&msp);

printf("输入女选手项目(<=20):");

scanf("%d",&wsp);

ntsp = msp + wsp;

phead = calloc(ntsp,sizeof(int));

pafirst = phead;

pasecond = phead;

input();

calculate();

output();

Save();

}

import javautil;

public class qiuzhi {

/

@param args

/

public static void main(String[] args) {

int pingjun=0,sum=0;

int fenshu[]= new int[100];

int temp=0;

Scanner input = new Scanner(Systemin);

int i=0;

for(;i<=100;i++){

Systemoutprintln("输入第"+(i+1)+"名学生分数(输入0跳出)");

fenshu[i]=inputnextInt();

if(fenshu[i]==0){

break;

}

}

for(int a = 0;a<i;a++){

for(int b = (a+1);b<=i;b++){

if(fenshu[a]<fenshu[b]){

temp = fenshu[a];

fenshu[a] = fenshu[b];

fenshu[b] = temp;

}

}

}

for(int a=0;a<i;a++){

Systemoutprintln(fenshu[a]);

sum=fenshu[a]+sum;

}

pingjun = sum/i;

Systemoutprintln("最高分"+fenshu[0]);

Systemoutprintln("最低分"+fenshu[i-1]);

Systemoutprintln("总分"+sum);

Systemoutprintln("平均分"+pingjun);

}

}

-----------------------------------

我不是很清楚你说的分散(distribution)和解中位数(median)

数是怎么回事。我把结果排列出来。具体你看一下。

或者解释一下分散还有中位数的计算方式我再给你具体试试写下

int a[20];

int i=0;

int min,max;//最大值和最小值坐标

int all = 0;

while(i < 20)

{

scanf("%d",a[i++]);

}

min = 0;

max = 0;

for(i=0;i<20;i++)

{

if(a[i] <min)

{

min = i;

}

if(a[i] > max)

{

max = i;

}

}

//最大值 和最小值 清0

a[min] = 0;

a[max] = 0;

for(i=0;i<20;i++)

{

all += a[i];

}

printf("平均值 =%f",all/20);

以上就是关于C++比赛分数编程 大家来看看全部的内容,包括:C++比赛分数编程 大家来看看、C++编写的随机分数计算、c语言程序设计一个评委打分系统 下面是要求等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10079563.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存