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

       随机顺序第一题“牛牛找工作”令我自闭,所以先从通过率高的找找自信

    1.游戏海报

    小明有26种游戏海报,用小写字母"a"到"z"表示。小明会把游戏海报装订成册(可能有重复的海报),册子可以用一个字符串来表示,每个字符就表示对应的海报,例如abcdea。小明现在想做一些“特别版”,然后卖掉。特别版就是会从所有海报(26种)中随机选一张,加入到册子的任意一个位置。

    那现在小明手里已经有一种海报册子,再插入一张新的海报后,他一共可以组成多少不同的海报册子呢?

    输入描述:

    海报册子的字符串表示,1 <= 字符串长度<= 20

    输出描述:

    一个整数,表示可以组成的不同的海报册子种类数
    示例1

    输入

    a 

    输出

    51

    要点:将牌X插入已有海报中时,如果已有海报已有X,左插和右插是一样效果

     1 using System;
     2 using System.Text;
     3 
     4 namespace GameAD
     5 {
     6     class combineAD
     7     {
     8         public static void Main(string[] args)
     9         {
    10             string str1= Console.ReadLine().ToString();
    11             if(str1.Length>=1&&str1.Length<=20)
    12             {
    13                 Console.WriteLine((str1.Length+1)*26-str1.Length);
    14             }
    15         }
    16     }
    17 }

    2.访友

    小易准备去拜访他的朋友,他的家在0点,但是他的朋友的家在x点(x > 0),均在一条坐标轴上。小易每一次可以向前走1,2,3,4或者5步。问小易最少走多少次可以到达他的朋友的家。

    输入描述:

    一行包含一个数字x(1 <= x <= 1000000),代表朋友家的位置。

    输出描述:

    一个整数,最少的步数。
    示例1

    输入

    4

    输出

    1
    示例2

    输入

    10

    输出

    2

    要点:visual studio 2019的math.ceiling和 math.floor返回值类型不是int,新版本错误?
     1 namespace copyfrom
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {
     7             int x = System.Convert.ToInt32(Console.ReadLine().ToString());
     8             if (x >= 1 && x <= 1000000)
     9             {
    10                 int steps = 0;
    11                 steps=System.Convert.ToInt32(Math.Ceiling(x/5.0));
    12                 Console.WriteLine(steps);
    13               
    14             }
    15         }
    16     }
    17 }

    3.员工考勤记录

    给定一个字符串来代表一个员工的考勤纪录,这个纪录仅包含以下两个字符:
    'A' : Absent,缺勤
    'P' : Present,到场
    如果一个员工的考勤纪录中不超过两个'A'(缺勤),那么这个员工会被奖赏。

    如果你作为一个员工,想在连续N天的考勤周期中获得奖赏,请问有多少种考勤的组合能够满足要求
    1 int n =System.Convert.ToInt32(Console.ReadLine());
    2            
    3 Console.WriteLine(n*(n-1)/2+n+1); 

    4.找零

    Z国的货币系统包含面值1元、4元、16元、64元共计4种硬币,以及面值1024元的纸币。现在小Y使用1024元的纸币购买了一件价值为N(0<N≤1024)N (0 < N le 1024)N(0<N1024)的商品,请问最少他会收到多少硬币?

    输入描述:

    一行,包含一个数N。

    输出描述:

    一行,包含一个数,表示最少收到的硬币数。
    示例1

    输入

    200

    输出

    17

    说明

    花200,需要找零824块,找12个64元硬币,3个16元硬币,2个4元硬币即可。
    1 public static void Main(string[] args)
    2         {
    3             int n =1024-System.Convert.ToInt32(Console.ReadLine());
    4             int a=n/64;
    5             int b=n%64/16;
    6             int c=n%64%16/4;
    7             int d=n%64%16%4;
    8             Console.WriteLine(a+b+c+d); 
    9         }

    5.非递减序列

    题目描述

    对于一个长度为n的整数序列,你需要检查这个序列是否可以是非递减序列,假如你最多可以改变其中的一个数。
    非递减序列的定义是:array[i]<=array[i+1], for 1<=i<n;

    输入描述:

    输入是一个长度为n的整数序列。

    输出描述:

    输出为; 是为1; 否为0
    示例1

    输入

    3 4 6 5 5 7 8

    输出

    1

    说明

    将6变成4, 序列变成 [3 4 4 5 5 7 8],符合非递减序列,因此输出1
    示例2

    输入

    3 4 6 5 4 7 8

    输出

    0

    备注:

    n的取值范围为: [2, 1000]
    要点:1.接收一组 整数
    2.字符串去除空格
    str.Replace(" ","");
    str.Trim();//头尾空格
     1 using System;
     2 using System.Text;
     3 
     4 namespace WorkAttendance
     5 {
     6     class Attendance
     7     {
     8         public static void Main(string[] args)
     9         {
    10             string str=Console.ReadLine();
    11             str.Replace(" ","");
    12             int[] seq=new int[str.Length]; 
    13             int n=0;
    14             foreach(char ch in str)
    15             {
    16                 seq[n]=ch;
    17             }
    18             int setno=0;
    19             for(;n<str.Length-1;n++)
    20             {
    21                  if(seq[n]>seq[n+1])
    22                  {
    23                       seq[n]=seq[n+1];
    24                       setno++;
    25                  }
    26             }
    27             if(setno>1)
    28             {Console.WriteLine("0");}
    29             else
    30             {Console.WriteLine("1");}
    31            
    32             
    33         }
    34     }
    35 }

     回顾:1.第五题虽然过了,但是逻辑上不是很完善。直接用char类型给整型数组元素赋值了。

  • 相关阅读:
    线性代数思维导图——3.向量
    微分中值定理的基础题型总结
    构造函数
    Python课程笔记(七)
    0241. Different Ways to Add Parentheses (M)
    0014. Longest Common Prefix (E)
    0013. Roman to Integer (E)
    0011. Container With Most Water (M)
    0010. Regular Expression Matching (H)
    0012. Integer to Roman (M)
  • 原文地址:https://www.cnblogs.com/yuanyuanhi/p/12149940.html
Copyright © 2011-2022 走看看