智线笔试
(必答)部⻔优化
某公司内有 4 个项⽬组,项⽬组 A、B、C、D,项⽬组A现有10⼈,项⽬组B现有7⼈,项⽬组C现
有5⼈,项⽬组D现有4⼈。为了实现跨项⽬组协作,公司决定每⽉从⼈数最多的项⽬组中抽调 3 ⼈
出来,到其他剩下 3 组中,每组 1 ⼈,这称之为⼀次调整优化(亦即经过第⼀次调整后,A组有7
⼈,B组有8⼈,C组有6⼈,D组有5⼈)。
那么请问,经过⼗年的优化调整后,各项⽬组各有⼏⼈?
编程求解该问题,并思考是否为最优解。
(必答)邀请码检测
某产品的⽤户注册邀请码为⼀串有⼩写字⺟和数字组成的字符串,字符串⻓度为16。当⽤户数据邀
请码的时候,系统需要对邀请码做有效性验证,假设验证规则如下:
1、 从序列号最后⼀位字符开始,逆向将奇数位(1、3、5等等)相加;
2、从序列号最后⼀位数字开始,逆向将偶数位数字,先乘以2(如果乘积为两位数,则将其减去
9),再求和;
3、将奇数位总和加上偶数位总和,结果可以被10整除;
4、⼩写字⺟对应数值,可由下⾯键值对确定;
[(a,1), (b,2), (c,3)…,(i,9), (j,1), (k, 2)…],亦即,按字⺟顺序,1-9循环。
输⼊:输⼊16位字符串,表示邀请码
输出:输出“ok”或者“error”
(必答)游戏币组合
⼩明的抽屉⾥有n个游戏币,总⾯值m,游戏币的设置有1分的,2分的,5分的,10分的,⽽在⼩明
所拥有的游戏币中有些⾯值的游戏币可能没有,求⼀共有多少种可能的游戏币组合⽅式?
输⼊:输⼊两个数n(游戏币的个数),m(总⾯值)。
输出:请输出可能的组合⽅式数;
(选答)有趣的两位数
有数学家发现⼀些两位数很有意思,⽐如,
34 * 86 = 43 * 68
也就是说,如果把他们的⼗位数和个位数交换,⼆者乘积不变。
编程求出满⾜该性质的两位数组合。
提示,暴⼒解法⾮最优解。
(选答)计算最⼤差值
有两组数,第⼀组数顺序固定,请编程实现让第⼆组数 相邻数字间的⼤⼩关系和第⼀组数相同,且
第⼆组相邻数字间的差值之和最⼤
下⾯给出⼀个示例
第⼀组数: 5 7 4 9
第⼆组数:1 2 3 4
第⼆组数排序结果:2 4 1 3
第⼆组数排序后的差值之和:7 = abs(2-4) + abs(4-1) + abs(1-3)
(选答)单链表处理
假设线性表 L = {A1, A2, A3, A4, …, An-2, An-1, An},采⽤带头节点的单链表保存。链接节点定义如
下:
typedef struct node {
int data;
struct node * next;
} NODE;
请设计⼀个算法,编程实现,重新排列 L 中的各节点,得到线性表 L’ = {A1, An, A2, An-1, A3, An2, … }。
(选答)系统设计题
1)请分析题⽬需求,给出你认为合理的技术⽅案,技术⽅案格式可参考原公司;
2)请充分通过题⽬展现你的设计⽅法,设计理念。对于关键的技术选型,给出适当注解;
需求描述:设计⼀个服务,任何⼈调⽤这个服务,都返回⼀个unique id,不能重复;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ZX { class Program { static void Main(string[] args) { //1.部⻔优化 Partment(10*12); //2.邀请码检测 CheckCode("aaaabbb111223456"); //3.游戏币组合 Coin(5, 11); //4.有趣的两位数 TwoNum(); //6.单链表处理 Node<int> node = new Node<int>(); Node<int> a1 = new Node<int>(1); Node<int> a2 = new Node<int>(2); Node<int> a3 = new Node<int>(3); Node<int> a4 = new Node<int>(4); Node<int> a5 = new Node<int>(5); node.Next = a1; a1.Next = a2; a2.Next = a3; a3.Next = a4; a4.Next = a5; LinkNode(node);//返回 1 5 2 4 3 //7.unique id 实现,使用 推特的 Snowflake 算法 //参考 https://github.com/mschuler/UniqueIdGenerator/blob/master/IdGenerator.net/Generator.cs } //发现规律 4月一循环 static void Partment(int months) { if (months<0) { return; } int temp = months % 4; int[] current = new int[4]; int[] m1=new int[] { 7, 8, 6, 5 }; int[] m2 = new int[] { 8, 5, 7, 6 }; int[] m3 = new int[] { 5, 6, 8, 7 }; int[] m4 = new int[] { 6, 7, 5, 8 }; switch (temp) { case 1: current = m1; break; case 2: current = m2; break; case 3: current = m3; break; case 0: current = m4; break; default: break; } Console.WriteLine("A组"+current[0]+ " B组"+current[1]+" C组"+current[2]+" D组"+current[3]); } static void CheckCode(string code) { if (code.Length!=16) { return; } //通过ascii 判断输入的是否规范48-57 97-122 for (int i = 0; i < code.Length; i++) { if ((code[i]>57&&code[i]<97)||code[i]<48||code[i]>122) { return; } } //奇和 int sum1 = 0; //偶和 int sum2 = 0; //a97 b98 ... for (int i = code.Length-1; i >=0; i--) { int n = code[i]; if (code[i]>57) { n = (code[i] - 96) % 7; } if (i%2==0) { sum2 += 2 * n > 9 ? 2 * n - 9 : 2 * n; } else { sum1 += n; } } Console.WriteLine((sum1 + sum2) % 10 == 0 ? "ok" : "error"); } static List<int> coins = new List<int>(); static List<int> m_coins = new List<int>() { 1, 2, 5, 10 }; //游戏币组合:从大游戏币开始依次往下循环 static void Coin(int n, int m) { //10分 for (int i = 0; i < m / n + 1; i++) { //5分 for (int j = 0; j < (m - 10 * i + 1); j++) { //2分 for (int k = 0; k < m - 10 * i - 5 * j + 1; k++) { //1分 int l = m - 10 * i - 5 * j - 2 * k; //如果所有游戏币相加==n 且 1分硬币不为负 if (i + j + k + l == n && l >= 0) { Console.WriteLine("10分有" + i + "个 " + "5分有" + j + "个 " + "2分有" + k + "个 " + "1分有" + l + "个"); } } } } } //ac=bd static void TwoNum() { int AShi; int AGe; int Bshi; int Bge; for (int num = 10; num < 100; num++) { for (int n = num + 1; n < 100; n++) { AShi = num / 10; AGe = num % 10; Bshi = n / 10; Bge = n % 10; //ac=bd if (AShi * Bshi == AGe * Bge) { Console.WriteLine("两个数为 "+AShi + ""+ AGe + ", "+ Bshi + ""+ Bge); } } } } static Node<int> LinkNode(Node<int> node) { //题目中没有说可不可以开辟新的空间。 List<Node<int>> nodes = new List<Node<int>>(); Node<int> p = node.Next; nodes.Add(p); while (p != null) { Node<int> q = p.Next; if (q!=null) { nodes.Add(q); } p.Next = node.Next; node.Next = p; p = q; } Node<int> nn= new Node<int>(); Node<int> newNode = new Node<int>(); for (int i = 0; i < Math.Ceiling( nodes.Count()/2.0f); i++) { Node<int> newNode1 = new Node<int>(); newNode1.Data=nodes[i].Data; if (i==0) { nn = newNode1; } newNode.Next = newNode1; if (nodes.Count() - 1 - i!=i) { Node<int> newNode2 = new Node<int>(); newNode2.Data = nodes[nodes.Count() - 1 - i].Data; newNode1.Next = newNode2; newNode = newNode2; } } return nn; } } internal class Node<T> { private int data; private Node<T> next; public int Data { get => data; set => data = value; } internal Node<T> Next { get => next; set => next = value; } public Node() { Data =data; Next = null; } public Node(int data) { this.Data = data; } } } |