431 条题解

  • 26
    @ 2016-12-10 10:15:10
    #include<iostream>
    using namespace std;
    int main()
    {
        string a,g;
        int b,c,f,n,money=0,result=0,sum=0;
        char d,e;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a>>b>>c>>d>>e>>f;
            money=0;
            if(b>80&&f>=1)
            money+=8000;
            if(b>85&&c>80)
            money+=4000;
            if(b>90)
            money+=2000;
            if(b>85&&e=='Y')
            money+=1000;
            if(c>80&&d=='Y')
            money+=850;
            sum+=money;
            if(result<money)
            {
                result=money;
                g=a;
            }
        }
        cout<<g<<endl<<result<<endl<<sum<<endl;
        return 0;
    }
    
  • 5
    @ 2009-04-04 09:45:58

    输入数据时千万要记得 占位符 加空格

    scanf("%s %d %d %c %c %d"

  • 3
    @ 2017-07-06 12:18:40

    pascal不哭抱紧我

    type
       Tnode=record
               nam:string;
               adv,cla,num,tot:longint;
               job,west:boolean;
             end;
     var
      st:string;
      N,i,p,q,ans,max:longint;
      a:array[1..100]of Tnode;
      begin
       readln(N);
        max:=0;
        for i:=1 to N do
          begin
            readln(st);
            a[i].job:=false;
            a[i].west:=false;
            p:=pos(' ',st);
            a[i].nam:=copy(st,1,p-1);
            delete(st,1,p);
            p:=pos(' ',st);
            val(copy(st,1,p-1),a[i].adv);
            delete(st,1,p);
            p:=pos(' ',st);
            val(copy(st,1,p-1),a[i].cla);
            delete(st,1,p);
            if st[1]='Y' then a[i].job:=true;
            if st[3]='Y' then a[i].west:=true;
            delete(st,1,4);
            val(st,a[i].num);
            if (a[i].adv>80)and(a[i].num>=1) then inc(a[i].tot,8000);
            if (a[i].adv>85)and(a[i].cla>80) then inc(a[i].tot,4000);
            if a[i].adv>90 then inc(a[i].tot,2000);
            if (a[i].adv>85)and(a[i].west) then inc(a[i].tot,1000);
            if (a[i].cla>80)and(a[i].job) then inc(a[i].tot,850);
            ans:=ans+a[i].tot;
            if a[i].tot>max then
             begin
               max:=a[i].tot;
               q:=i;
             end;
          end;
          writeln(a[q].nam);
          writeln(a[q].tot);
          write(ans);
       end.
    
    
    • @ 2018-01-31 20:22:03

      pascal还有个字符串处理😂

  • 1
    @ 2018-12-19 21:50:03

    用sort会因为名字问题过不了,
    改用stable_sort。

    • Accepted
    • # 状态 耗时 内存占用
    • #1 Accepted 1ms 336.0 KiB
    • #2 Accepted 1ms 216.0 KiB
    • #3 Accepted 1ms 216.0 KiB
    • #4 Accepted 1ms 220.0 KiB
    • #5 Accepted 1ms 344.0 KiB
    • #6 Accepted 1ms 216.0 KiB
    • #7 Accepted 1ms 344.0 KiB
    • #8 Accepted 1ms 344.0 KiB
    • #9 Accepted 1ms 216.0 KiB
    • #10 Accepted
    #include<iostream>
    #include<algorithm>
    #include<string>
    using namespace std;
    //呵呵
    //大神万岁
    //分割线--------------------------------------------------$
    //结构定义区
    struct student{
        int qm,bj,lw;
        int money;
        bool gb,xb;
        string name;
        student(string s,int q,int b,char g,char x,int l)
        {
            name=s;
            qm=q;
            bj=b;
            if(g=='Y') gb=true;
            else gb=false;
            if(x=='Y') xb=true;
            else xb=false;
            lw=l;
            money=0;
            if(qm>80 && lw>=1) money+=8000;
            if(qm>85 && bj>80) money+=4000;
            if(qm>90) money+=2000;
            if(qm>85 && xb==true) money+=1000;
            if(bj>80 && gb==true) money+=850;
        }
        student()
        {
            student("",0,0,'N','N',0);
        }
    }; 
    struct cmp{
        bool operator() (student a,student b)
        {
            return a.money>b.money;
        }
    };
    //全局变量区
    student stu[101];
    int n,all;
    //函数声明区
    
    //主函数开始!
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>n;
        for(int i=0;i<n;i++)
        {
            string str;
            int a,b,e;
            char c,d;
            cin>>str>>a>>b>>c>>d>>e;
            stu[i]=student(str,a,b,c,d,e);
            all+=stu[i].money;
        }
        stable_sort(stu,stu+n,cmp());
        cout<<stu[0].name<<endl<<stu[0].money<<endl<<all<<endl;
        return 0;
    }
    //函数实现区
    
  • 1
    @ 2018-12-18 01:00:28

    #include <stdio.h>
    #include <stdlib.h>
    struct student
    {
    char name[21];
    int aver;
    int ban;
    char gb;
    char west;
    int num;
    int money;
    } stu[101];
    int cmp(const void *a,const void b)
    {
    return (
    (struct student )b).money-((struct student *)a).money;
    }
    int main()
    {
    int N,i,j;
    scanf("%d",&N);
    for(i=0; i<N; i++){
    scanf("%s %d %d %c %c %d",stu[i].name,&stu[i].aver,&stu[i].ban,&stu[i].gb,&stu[i].west,&stu[i].num);
    stu[i].money=0;
    if(stu[i].aver>80&&stu[i].num>=1) stu[i].money+=8000;
    if(stu[i].aver>85&&stu[i].ban>80) stu[i].money+=4000;
    if(stu[i].aver>90) stu[i].money+=2000;
    if(stu[i].west=='Y'&&stu[i].aver>85) stu[i].money+=1000;
    if(stu[i].ban>80&&stu[i].gb=='Y') stu[i].money+=850;
    }
    int sum=0;
    for(j=0; j<N; j++)
    sum+=stu[j].money;
    qsort(stu,N,sizeof(struct student),cmp);
    printf("%s\n",stu[0].name);
    printf("%d\n",stu[0].money);
    printf("%d\n",sum);
    }

  • 1
    @ 2018-11-07 14:42:46

    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    string name[101]; //学生名字
    int qimo[101],banji[101]; //期末成绩,班级成绩
    char xuesheng[101],xibu[101];//学生干部,西部地区
    int lunwen[101]; //论文数量
    int n,ans=0; //n个学生,总的奖学金
    int money; //这就是神奇之处,不需要存储每个学生的奖学金
    int max1=-1; //记录最多奖学金
    string maxstudent; //记录最多奖学金获得者

    cin>>n;

    for(int i=1;i<=n;i++) //开始循环啦
    {
    money=0; //刚开始每个人都没有钱

    cin>>name[i]>>qimo[i]>>banji[i]>>xuesheng[i]>>xibu[i]>>lunwen[i]; //输入一遍
    if(qimo[i]>80 && lunwen[i]>=1) money+=8000;
    if(qimo[i]>85 && banji[i]>80) money+=4000;
    if(qimo[i]>90) money+=2000;
    if(qimo[i]>85 && xibu[i]=='Y') money+=1000;
    if(banji[i]>80 && xuesheng[i]=='Y') money+=850;

    ans+=money; //总的奖学金要加上去

    if(money>max1) //计算最多奖学金,因为要输出最先出现的学生,所以等于就不用了
    {
    max1=money;
    maxstudent=name[i];//记录奖学金最多者的姓名
    }

    }

    cout<<maxstudent<<endl<<max1<<endl<<ans;//输出,结束

    return 0; //没有renturn 0也能AC,不过最好加上
    }

  • 1
    @ 2018-11-05 13:48:26

    简单题,结构体+排序一边走起

    #include<bits/stdc++.h>
    using namespace std;
    struct student{
        string name;
        int cj1,cj2;
        char gb,xb;
        int lw;
        int num,ans=0;
    }d[100000];
    int n,total=0;
    bool cmp(student a,student b)
    {
        if(a.ans==b.ans) return a.num<b.num;
        else return a.ans>b.ans;
    }
    int main()
    {
        cin>>n;
        for(int i=1; i<=n; i++)
        {
            cin>>d[i].name>>d[i].cj1>>d[i].cj2>>d[i].gb>>d[i].xb>>d[i].lw;
            d[i].num=i;
            if(d[i].cj1>80 && d[i].lw>=1) d[i].ans+=8000;
            if(d[i].cj1>85 && d[i].cj2>80) d[i].ans+=4000;
            if(d[i].cj1>90) d[i].ans+=2000;
            if(d[i].xb=='Y' && d[i].cj1>85) d[i].ans+=1000;
            if(d[i].gb=='Y' && d[i].cj2>80) d[i].ans+=850;
            total+=d[i].ans;
        }
        sort(d+1,d+n+1,cmp);
        cout<<d[1].name<<endl<<d[1].ans<<endl<<total<<endl;
        return 0;
    }
    
  • 1
    @ 2018-04-06 12:42:47
    using System;
    using System.Collections.Generic;
    
    namespace ConsoleApp16
    {
        class Program
        {
            static void Main(string[] args)
            {
                int a = Convert.ToInt32(Console.ReadLine());
    
                List<Student> b = new List<Student>();
    
                for(int i=0;i<a;i++)
                {
                    string[] l = Console.ReadLine().Split(' ');
    
                    b.Add(new Student { name = l[0], a = Convert.ToInt32(l[1]), b = Convert.ToInt32(l[2]), c = (l[3] == "Y" ? true : false), d = (l[4] == "Y" ? true : false), e = Convert.ToInt32(l[5]) });
                }
    
                b.Sort();          
    
                Console.WriteLine(b[0]);
    
                Console.WriteLine(b[0].Money);
    
                int c = 0;
    
                foreach(Student d in b)
                {
                    c += d.Money;
                }
    
                Console.WriteLine(c);
            }
        }
        public class Student:IComparable
        {
            public int a;
    
            public int b;
    
            public bool c;
    
            public bool d;
    
            public int e;
    
            public string name;
    
            public int Money => (M1() ? 8000 : 0) + (M2() ? 4000 : 0) + (M3() ? 2000 : 0) + (M4() ? 1000 : 0) + (M5() ? 850 : 0);
    
            public bool M1()
            {
                if(a>80&&e>=1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public bool M2()
            {
                if(a>85&&b>80)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public bool M3()
            {
                if(a>90)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public bool M4()
            {
                if(a>85&&d)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public bool M5()
            {
                if(b>80&&c)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public static bool operator >(Student a, Student b) => (a.Money > b.Money ? true : false);
    
            public static bool operator <(Student a, Student b) => (a.Money < b.Money ? true : false);
    
            public override string ToString()
            {
                return name;
            }
    
            public int CompareTo(object obj)
            {
                if(obj is Student)
                {
                    Student a = obj as Student;
    
                    return a.Money - Money;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
    
    
    
  • 1
    @ 2018-01-06 23:05:28

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <string.h>
    struct student
    {
    char name[20];
    int qscore;
    int bscore;
    char bangan;
    char xibu;
    int lunwen;
    int z;

    }stu[100];

    int main()
    {
    int n,i,j=0,k=0;
    struct student temp;
    char ch;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    scanf("%s %d %d %c %c %d",stu[i].name,&stu[i].qscore,&stu[i].bscore,&stu[i].bangan,&stu[i].xibu,&stu[i].lunwen);
    stu[i].z=0;
    if(stu[i].qscore>80&&stu[i].lunwen>=1)
    stu[i].z=stu[i].z+8000;
    if(stu[i].bscore>80&&stu[i].qscore>85)
    stu[i].z=stu[i].z+4000;
    if(stu[i].qscore>90)
    stu[i].z=stu[i].z+2000;
    if(stu[i].xibu=='Y'&&stu[i].qscore>85)
    stu[i].z=stu[i].z+1000;
    if(stu[i].bangan=='Y'&&stu[i].bscore>80)
    stu[i].z=stu[i].z+850;
    k=k+stu[i].z;
    }
    for(i=0;i<n-1;i++)
    {
    for(j=0;j<n-1;j++)
    {
    if(stu[j].z<stu[j+1].z)
    {
    temp=stu[j];
    stu[j]=stu[j+1];
    stu[j+1]=temp;
    }
    }
    }
    temp=stu[0];
    for(i=1;stu[i].z==temp.z&&i<n;i++)
    {
    if(strcmp(stu[i].name,temp.name)<0)
    temp=stu[i];
    }
    printf("%s\n%d\n%d",temp.name,temp.z,k);
    return 0;
    }

  • 1
    @ 2016-10-14 11:46:28
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<string>
    using namespace std;
    int tot=0,n;
    struct NodeT{
        string name;
        int qm,bp,lwn,reward;
        char xg,xs;
    }node[105];//结构体node存数据
    
    /*bool comp(NodeT x,NodeT y){
        if(x.reward!=y.reward)return x.reward>y.reward;
        return x.name<y.name;
    }比较函数 (不需要)delete
    */ 
    void solve(){
        for(int i=1;i<=n;i++){
            node[i].reward=0;
            if(node[i].qm>80&&node[i].lwn>=1)node[i].reward+=8000;
            if(node[i].qm>85&&node[i].bp>80)node[i].reward+=4000;
            if(node[i].qm>90)node[i].reward+=2000;
            if(node[i].qm>85&&node[i].xs=='Y')node[i].reward+=1000;
            if(node[i].bp>80&&node[i].xg=='Y')node[i].reward+=850;
        }//逐个输入
        node[0].reward=0;//***初始化为零*** 打擂 求出最大值
        for(int i=1;i<=n;i++)
        {
            if(node[i].reward>node[0].reward)
            {
                node[0].name=node[i].name;
                node[0].reward=node[i].reward;
            }
            tot+=node[i].reward;//求和
        }
        cout<<node[0].name<<endl<<node[0].reward<<endl<<tot<<endl;//输出
    }
    
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++)cin>>node[i].name>>node[i].qm>>node[i].bp>>node[i].xg>>node[i].xs>>node[i].lwn;
        solve();
        return 0;
    }
    
  • 0
    @ 2019-01-14 19:59:05
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int n,f,b,ls,ans;char x,y;
    struct node{
        char a[23];int sum,id;
    }a[1010];
    bool cmp(node x,node y){
        if (x.sum!=y.sum) return x.sum>y.sum;
        else return x.id<y.id;
    }
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%s %d %d %c %c %d",&a[i].a,&f,&b,&x,&y,&ls);
            int s=0;
            if (f>80&&ls>0) s+=8000;
            if (f>85&&b>80) s+=4000;
            if (f>90) s+=2000;
            if (f>85&&y=='Y') s+=1000;
            if (b>80&&x=='Y') s+=850;
            a[i].sum=s;a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
            ans+=a[i].sum;
        printf("%s\n%d\n%d\n",a[1].a,a[1].sum,ans);
        return 0;//ok
    }
    
  • 0
    @ 2019-01-14 19:59:05
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int n,f,b,ls,ans;char x,y;
    struct node{
        char a[23];int sum,id;
    }a[1010];
    bool cmp(node x,node y){
        if (x.sum!=y.sum) return x.sum>y.sum;
        else return x.id<y.id;
    }
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%s %d %d %c %c %d",&a[i].a,&f,&b,&x,&y,&ls);
            int s=0;
            if (f>80&&ls>0) s+=8000;
            if (f>85&&b>80) s+=4000;
            if (f>90) s+=2000;
            if (f>85&&y=='Y') s+=1000;
            if (b>80&&x=='Y') s+=850;
            a[i].sum=s;a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
            ans+=a[i].sum;
        printf("%s\n%d\n%d\n",a[1].a,a[1].sum,ans);
        return 0;//ok
    }
    
  • 0
    @ 2019-01-11 11:54:13

    #include<iostream>
    using namespace std;
    int main()
    {
    string a,g;
    int b,c,f,n,money=0,result=0,sum=0;
    char d,e;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>a>>b>>c>>d>>e>>f;
    money=0;
    if(b>80&&f>=1)
    money+=8000;
    if(b>85&&c>80)
    money+=4000;
    if(b>90)
    money+=2000;
    if(b>85&&e=='Y')
    money+=1000;
    if(c>80&&d=='Y')
    money+=850;
    sum+=money;
    if(result<money)
    {
    result=money;
    g=a;
    }
    }
    cout<<g<<endl<<result<<endl<<sum<<endl;
    return 0;
    }

  • 0
    @ 2018-11-26 19:37:51

    #include <iostream>
    using namespace std;
    int main()
    {
    int n,i,j1=0,j2=0,j3=0;//学生数 当前学生奖学金 最高奖学金 总奖学金
    string m1,m2;//名字
    int q1,q2,p1,p2,l1,l2;//期末 评议 论文
    char g1,g2,x1,x2;//干部 西部
    cin>>n;
    for(i=0;i<n;i++)
    {
    j1=0;
    cin>>m1>>q1>>p1>>g1>>x1>>l1;
    if(q1>80&&l1>=1)
    j1=j1+8000;
    if(q1>85&&p1>80)
    j1=j1+4000;
    if(q1>90)
    j1=j1+2000;
    if(q1>85&&x1=='Y')
    j1=j1+1000;
    if(p1>80&&g1=='Y')
    j1=j1+850;
    if(j1>j2)
    {
    j2=j1;m2=m1;
    }
    j3+=j1;
    }
    cout<<m2<<endl<<j2<<endl<<j3<<endl;
    return 0;
    }

  • 0
    @ 2018-11-25 17:26:07

    c++代码
    #include<bits/stdc++.h>
    using namespace std;
    int n,sum,ans=1;
    struct Int{
    char mz[20],gb,xb;
    int qm,py,lv,tsum;
    void input(){
    cin>>mz;
    cin>>qm;
    cin>>py;
    cin>>gb;
    cin>>xb;
    cin>>lv;
    }
    void output(){
    printf("%s\n",mz);
    printf("%d\n",tsum);
    }
    void ys(){
    if(qm>80 && lv>=1){
    sum+=8000;
    tsum+=8000;
    }
    }
    void ws(){
    if(qm>85 && py>80){
    sum+=4000;
    tsum+=4000;
    }
    }
    void cj(){
    if(qm>90){
    sum+=2000;
    tsum+=2000;
    }
    }
    void xbj(){
    if(qm>85 && xb=='Y'){
    sum+=1000;
    tsum+=1000;
    }
    }
    void bj(){
    if(py>80 && gb=='Y'){
    sum+=850;
    tsum+=850;
    }
    }
    }a[101];
    int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    a[i].input();
    a[i].ys();
    a[i].ws();
    a[i].cj();
    a[i].xbj();
    a[i].bj();
    }
    for(int i=2;i<=n;i++)
    if(a[ans].tsum<a[i].tsum) ans=i;
    a[ans].output();
    printf("%d",sum);
    return 0;
    }

  • 0
    @ 2018-10-10 16:07:48

    #include "stdafx.h"
    #include <iostream>
    #include <string>

    using namespace std;

    struct stu {
    string name;
    int qm, bj, lw;
    char gb, xb;
    int jx=0;

    };
    int main()
    {
    using namespace std;

    int rs;
    cin >> rs;

    stu* xs = new stu[rs];

    for (int i = 0; i < rs; i++) {
    cin >> xs[i].name >> xs[i].qm >> xs[i].bj >> xs[i].gb >> xs[i].xb >> xs[i].lw;
    }

    for (int i = 0; i < rs; i++) {
    if (xs[i].qm>80 && xs[i].lw >= 1) xs[i].jx += 8000;
    if (xs[i].qm>85 && xs[i].bj>80) xs[i].jx += 4000;
    if (xs[i].qm>90) xs[i].jx += 2000;
    if (xs[i].qm>85 && xs[i].xb == 'Y') xs[i].jx += 1000;
    if (xs[i].bj>80) xs[i].jx += 850;
    }

    int max = 0;
    int a = 0;
    for (int i = 0; i<rs; i++) {
    a += xs[i].jx;
    if (xs[i].jx>xs[max].jx) {
    max = i;
    }
    }
    cout << xs[max].name << endl;
    cout << xs[max].jx << endl;
    cout << a << endl;

    }

  • 0
    @ 2018-10-09 10:43:55
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    struct student{
        string name;
        int qimo;
        int banping;
        char monitor;
        char west;
        int lun;
        int money=0;
        int num;
    };
    bool cmp(student x,student y){
        if(x.money !=y.money ) return x.money >y.money ;
        return x.num <y.num ;
    }
    int main(){
        int n;
        scanf("%d",&n);
        student ss[n];
        long long sum=0;
        for(int i=0;i<n;i++){
            ss[i].num =i;
            cin>>ss[i].name >>ss[i].qimo >>ss[i].banping >>ss[i].monitor >>ss[i].west >>ss[i].lun ;
            if(ss[i].qimo >80&&ss[i].lun >=1) ss[i].money +=8000;
            if(ss[i].qimo >85&&ss[i].banping >80) ss[i].money +=4000;
            if(ss[i].qimo >90) ss[i].money +=2000;
            if(ss[i].qimo >85&&ss[i].west=='Y') ss[i].money +=1000;
            if(ss[i].banping >80&&ss[i].monitor =='Y') ss[i].money +=850;
            sum+=ss[i].money ;
        }
        sort(ss,ss+n,cmp);
        cout<<ss[0].name <<endl<<ss[0].money <<endl<<sum<<endl;
        return 0;
    }
    
  • 0
    @ 2018-09-27 21:07:34

    WA大家能帮我看看怎么错了吗。
    ```cpp
    #include<iostream>
    #include<string>
    using namespace std;
    class stu
    {
    public:
    stu()
    {
    name ="kk" ;
    qm = 0;
    py = 0;
    gb = 'l';
    xb = 'l';
    lw = 0;
    }

    stu (string n,int q,int p,char g,char x,int l)
    {
    name =n ;
    qm = q;
    py = p;
    gb = g;
    xb = x;
    lw = l;

    }
    void xg(string n,int q,int p,char g,char x,int l)
    {

    name =n ;
    qm = q;
    py = p;
    gb = g;
    xb = x;
    lw = l;
    }

    void shuchu()
    {
    cout<<name<<endl;
    }
    int jxj()
    { int s=0;
    if(qm>80&&lw>0) s+=8000;
    if(qm>85&&py>80) s+=4000;
    if(qm>90) s+=2000;
    if(qm>85&&xb=='Y') s+=1000;
    if(py>80&&gb=='Y') s+=850;
    return s;
    }

    private:
    string name;
    int qm;
    int py;
    char gb;
    char xb;
    int lw;
    };
    int main()
    { stu s[101];
    int N;
    cin>>N;
    int q,p,l,nam=0;
    string n;
    char g,x;
    for(int i = 0;i<N;i++)
    {
    cin>>n>>q>>p>>g>>x>>l;
    s[i].xg(n,q,p,g,x,l);
    }
    for(int m = 0;m<N;m++)
    {
    nam+=s[m].jxj();
    if(s[m].jxj()>s[100].jxj())
    s[100]=s[m];

    }

    s[100].shuchu();
    cout<<s[99].jxj()<<endl<<nam;
    return 0;
    }

  • 0
    @ 2018-09-12 22:03:06
    #[derive(Debug)]
    struct Student {
        name: String,
        ave_score: i32,
        appraisal_score: i32,
        is_cadre: bool,
        is_west: bool,
        paper_count: i32,
    }
    impl Student {
        fn get_award(&self) -> usize {
            let mut award: usize = 0;
            if self.ave_score > 80 && self.paper_count >= 1 {
                award += 8000;
            };
            if self.ave_score > 85 && self.appraisal_score > 80 {
                award += 4000;
            };
            if self.ave_score > 90 {
                award += 2000;
            };
            if self.ave_score > 85 && self.is_west {
                award += 1000;
            };
            if self.appraisal_score > 80 && self.is_cadre {
                award += 850;
            };
            award
        }
    }
    use std::vec::Vec;
    fn main() {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let student_count: usize = buf.trim().parse().unwrap();
        let mut students: Vec<Student> = Vec::with_capacity(student_count);
        for _ in 0..student_count {
            buf.clear();
            std::io::stdin().read_line(&mut buf).unwrap();
            let res: Vec<&str> = buf.trim().split(" ").collect(); 
            let name = res.get(0).unwrap();
            let ave_score: i32 = res.get(1).unwrap().parse().unwrap();
            let appraisal_score: i32 = res.get(2).unwrap().parse().unwrap();
            let is_cadre = match res.get(3).unwrap() {
                &"Y" => true,
                &"N" => false,
                _ => false,
            };
            let is_west = match res.get(4).unwrap() {
                &"Y" => true,
                &"N" => false,
                _ => false,
            };
            let paper_count: i32 = res.get(5).unwrap().parse().unwrap();
            students.push(Student {
                name: String::from(*name),
                ave_score:ave_score,
                appraisal_score:appraisal_score,
                is_cadre:is_cadre,
                is_west:is_west,
                paper_count:paper_count,
            })
        }
        let max_award_student = students.iter().max_by_key(|s| s.get_award()).unwrap();
        println!("{}", max_award_student.name);
        println!("{}", max_award_student.get_award());
        println!("{}", students.iter().fold(0, |acc,s| acc+s.get_award()));
    }
    
    
    
  • 0
    @ 2018-09-07 20:43:32

    #include<iostream>
    using namespace std;
    struct tstudent{
    string name,m,n;
    int f,c,num;
    };
    int N,sum,n1=0,n2=0,sum1;
    tstudent a[601];
    int jiang(int x){
    sum=0;
    if(a[x].f>80&&a[x].num>=1) sum+=8000;
    if(a[x].f>85&&a[x].c>80) sum+=4000;
    if(a[x].f>90) sum+=2000;
    if(a[x].f>85&&a[x].n=="Y") sum+=1000;
    if(a[x].c>80&&a[x].m=="Y") sum+=850;
    return sum;
    }
    int main(){
    cin>>N;
    for(int i=0;i<N;i++){
    cin>>a[i].name>>a[i].f>>a[i].c>>a[i].m>>a[i].n>>a[i].num;
    }
    for(int j=0;j<N;j++){
    if(jiang(j)>n2){
    n2=jiang(j);
    n1=j;
    }
    sum1+=jiang(j);
    }
    cout<<a[n1].name<<endl<<jiang(n1)<<endl<<sum1;
    return 0;

    }

信息

ID
1001
难度
5
分类
模拟 点击显示
标签
递交数
32239
已通过
10816
通过率
34%
上传者