zoukankan      html  css  js  c++  java
  • 牛客网-2019年校招真题-通过率降序(二)

    6.表达式求值

    今天上课,老师教了小易怎么计算加法和乘法,乘法的优先级大于加法,但是如果一个运算加了括号,那么它的优先级是最高的。例如:
    1+2*3=7
    1*(2+3)=5
    1*2*3=6
    (1+2)*3=9
    现在小易希望你帮他计算给定3个数a,b,c,在它们中间添加"+", "*", "(", ")"符号,能够获得的最大值。

    输入描述:

    一行三个数a,b,c (1 <= a, b, c <= 10)

    输出描述:

    能够获得的最大值
    示例1

    输入

    1 2 3

    输出

    9
     1 using System;
     2 using System.Text;
     3 using System.Text.RegularExpressions;
     4 namespace AAAAA
     5 {
     6     class AA
     7     {
     8         public static void Main(string[] args)
     9         {
    10             string str = Console.ReadLine();
    11             string[] arr = Regex.Split(str, " ");
    12             int[] shuZu=new int[3];
    13             int n = 0;
    14             int sum = 0;
    15             foreach (string str2 in arr)
    16             {
    17                 shuZu[n]=Convert.ToInt32(str2);
    18                 n++;
    19             }
    20             int[] result=new int[6];
    21             result[0]=shuZu[0]+shuZu[1]+shuZu[2];
    22             result[1]=shuZu[0]*shuZu[1]*shuZu[2];
    23             result[2]=shuZu[0]*shuZu[1]+shuZu[2];
    24             result[3]=shuZu[0]+shuZu[1]*shuZu[2];
    25             result[4]=(shuZu[0]+shuZu[1])*shuZu[2];
    26             result[5]=shuZu[0]*(shuZu[1]+shuZu[2]);
    27             Console.WriteLine(Math.Max(result[0],Math.Max(result[1],Math.Max(result[2],Math.Max(result[3],Math.Max(result[4],result[5]))))));
    28         }
    29     }
    30 }

    7.模数求和

    现给定n个整数,并定义一个非负整数m,且令f(m) = (m%a1)+(m%a2)+...+(m%an)。
    此处的X % Y的结果为X除以Y的余数。
    现请你找出一个m,求出f(m)的最大值。

    输入描述:

    输入包含两行,第一行为一正整数n,(1<n<=3000)
    第二行为n个整数a
    1
    ,a
    2
    ,...,a
    n
    ,其中(2<=a
    i
    <=10^5)

    输出描述:

    输出仅包含一行,输出f(m)的最大值
    示例1

    输入

    3
    3 4 6

    输出

    10

    说明

    就样例而言,当m取11时可取得最大值。
     1 using System;
     2 using System.Text;
     3 using System.Text.RegularExpressions;
     4 
     5 namespace WorkAttendance
     6 {
     7     class Attendance
     8     {
     9         public static void Main(string[] args)
    10         {
    11            int m = System.Convert.ToInt32(Console.ReadLine());
    12             string str = Console.ReadLine();
    13             string[] arr = Regex.Split(str, " ");
    14             int n = 0;
    15             int sum = 0;
    16             foreach (string str2 in arr)
    17             {
    18                 sum += Convert.ToInt32(str2) - 1;
    19                 n++;
    20             }
    21             Console.WriteLine(sum); 
    22         }
    23     }
    24 }

     8.二进制中有多少个一

    把一个32-bit整型转成二进制,其中包含多少个1,比如5的二进制表达是101,其中包含2个1

    输入描述:

    输入为整型(十进制),只需兼容32-bit即可,如5、32

    输出描述:

    输出为字符串,如“2”、“1”
    示例1

    输入

    5

    输出

    2

    说明

    5的二进制是101,其中包含2个1
     1 using System;
     2 using System.Text;
     3 namespace AAAAA
     4 {
     5     class AA
     6     {
     7         public static void Main(string[] args)
     8         {
     9             int a = Convert.ToInt32(Console.ReadLine());
    10             string str = Convert.ToString(a, 2);
    11             int c = 0;
    12             foreach (char ch in str)
    13             {
    14                 if (ch == '1')
    15                 {
    16                     c++;
    17                 }
    18             }
    19             Console.WriteLine(c);
    20             Console.ReadKey();
    21         }
    22     }
    23 }

    9.
    有一个无限长的数字序列1,2,2,3,3,3,4,4,4,4,5,5,5,5,5。。。(数字序列从1开始递增,且数字k在该序列中正好出现k次),求第n项是多少

    输入描述:

    输入为一个整数n

    输出描述:

    输出一个整数,即第n项的值
    示例1

    输入

    4

    输出

    3

     1  public static void Main(string[] args)
     2         {
     3              int n = Convert.ToInt32(Console.ReadLine());
     4              int i=0;
     5              for(;;i++)
     6              {
     7                   if(n<=i*(i+1)/2&&n>(i-1)*i/2)
     8                   {
     9                      Console.WriteLine(i);
    10                       break;
    11                    }
    12              }
    13         }

    10.
  • 相关阅读:
    第一节,Django+Xadmin打造上线标准的在线教育平台—创建用户app,在models.py文件生成3张表,用户表、验证码表、轮播图表
    Tensorflow 错误:Unknown command line flag 'f'
    Python 多线程总结
    Git 强制拉取覆盖本地所有文件
    Hive常用函数 傻瓜学习笔记 附完整示例
    Linux 删除指定大小(范围)的文件
    Python 操作 HBase —— Trift Trift2 Happybase 安装使用
    梯度消失 梯度爆炸 梯度偏置 梯度饱和 梯度死亡 文献收藏
    Embedding 文献收藏
    深度学习在CTR预估中的应用 文献收藏
  • 原文地址:https://www.cnblogs.com/yuanyuanhi/p/12150625.html
Copyright © 2011-2022 走看看