zoukankan      html  css  js  c++  java
  • 【高精度】Oliver的成绩

    问题 E: 【高精度】Oliver的成绩

    时间限制: 1 Sec  内存限制: 64 MB
    提交: 5  解决: 4
    [提交] [状态] [讨论版] [命题人:外部导入]

    题目描述

    Oliver进入初中后,觉得自己不能总是玩了,应该要好好学习了。正好一次考试结束,Oliver想知道自己的语文、数学、英语成绩分别与语文年级第一、数学年级第一、英语年级第一的相差多少。
    由于Oliver所在年级有N个人,所以Oliver想请你编个程序帮帮他。

    输入

    共3N+4行,第1至第3行分别为Oliver的语文、数学、英语成绩(位数M),第4行为N,以下3N行,每行一个数(它们的位数是M),分别为第N个同学的语文、数学、英语成绩。即:Oliver的语文数学英语
    N
    第一个人的语文
    数学
    英语
    第二个人的语文

    输出

    共1行,有三个数,分别为Oliver的语文、数学、英语成绩与年级第一的差。
    如果Oliver是第一,则输出0。

    样例输入

    10
    10
    10
    3
    0
    80
    0
    40
    0
    0
    0
    0
    100
    
    

    样例输出

    30 70 90 
    

    提示

    对于100%的数据,0<N<100000<M<30,且都为整数。

     

     1 #include <iostream>
     2 #include<string>
     3 #include<algorithm>
     4 #include<cstring>
     5 using namespace std;
     6 string s1,s2,s3,t1,t2,t3,max1,max2,max3;
     7 int n,a[50],b[50],c[50],len;
     8 string getMax(string x,string y)
     9 {
    10     int lenx=x.size(),leny=y.size();
    11     if(lenx==leny)
    12     {
    13         if(x<y)
    14             return y;
    15         else
    16             return x;
    17     }
    18     else if(lenx<leny)
    19         return y;
    20     else
    21         return x;
    22 }
    23 void fun(string x,string y)
    24 {
    25     memset(a,0,sizeof(a));
    26     memset(b,0,sizeof(b));
    27     memset(c,0,sizeof(c));
    28     int lenx=x.size(),leny=y.size();
    29     if(lenx>leny||(lenx==leny&&x>y))
    30     {
    31         for(int i=lenx-1;i>=0;i--)
    32             a[lenx-i-1]=x[i]-'0';
    33         for(int i=leny-1;i>=0;i--)
    34             b[leny-i-1]=y[i]-'0';
    35         len=lenx;
    36 //        cout<<len<<endl;
    37         for(int i=0;i<len;i++)
    38         {
    39             c[i]+=(a[i]-b[i]);
    40             if(c[i]<0)
    41             {
    42                 c[i]+=10;
    43                 c[i+1]--;
    44             }
    45         }
    46         while(c[len]==0)
    47         {
    48             len--;
    49         }
    50     }
    51     else
    52     {
    53         c[0]=0;
    54         len=0;
    55     }
    56 }
    57 int main()
    58 {
    59     cin>>s1>>s2>>s3;
    60     max1=s1;
    61     max2=s2;
    62     max3=s3;
    63     cin>>n;
    64     while(n--)
    65     {
    66         cin>>t1>>t2>>t3;
    67         max1=getMax(max1,t1);
    68         max2=getMax(max2,t2);
    69         max3=getMax(max3,t3);
    70     }
    71 
    72     fun(max1,s1);
    73     for(int i=len;i>=0;i--)
    74         cout<<c[i];
    75     cout<<" ";
    76     fun(max2,s2);
    77     for(int i=len;i>=0;i--)
    78         cout<<c[i];
    79     cout<<" ";
    80     fun(max3,s3);
    81     for(int i=len;i>=0;i--)
    82         cout<<c[i];
    83     cout<<endl;
    84 //    cout<<s1<<" "<<s2<<" "<<s3<<" "<<endl;
    85 //    cout<<max1<<" "<<max2<<" "<<max3<<endl;
    86     return 0;
    87 }
    View Code

     

     

    如有错误,请指正,感谢!
  • 相关阅读:
    Leetcode 92. Reverse Linked List II
    Leetcode 206. Reverse Linked List
    Leetcode 763. Partition Labels
    Leetcode 746. Min Cost Climbing Stairs
    Leetcode 759. Employee Free Time
    Leetcode 763. Partition Labels
    搭建数据仓库第09篇:物理建模
    Python进阶篇:Socket多线程
    Python进阶篇:文件系统的操作
    搭建数据仓库第08篇:逻辑建模–5–维度建模核心之一致性维度2
  • 原文地址:https://www.cnblogs.com/scott527407973/p/9314495.html
Copyright © 2011-2022 走看看