阿里4.15笔试 晚上19:00~20:30,时长90min!!!
编程环境***ACM模式。
三种题型分开,一种题型全部提交后才能做下一种题型,那么这个题型就不能修改了。所以一定要先做选择题,后做编程题!!!
考察的内容是八股文,包括但不限于Linux、MySQL、网络协议等。
由于我没复习八股,直接GG……

已知这个输入法的规则是这样的:
按一下2,会准备输出'A',如果再按一下2,会准备输出'B。此时若按了其他键,那么会把当前准备的字符输出并准备下一个字母请注意,1没有对应任何字母,但按1的时候会直接输出当前准备输出的字母。
小红拿到了一个按键串,请你输出小红最终打印的字母。(具体规则请参考样例1)
一个长度不超过100000的,仅包含'1'到'9'的数字串。
一个仅包含大写字母的字符串。保证至少输出一个字符。
输入:
1221193333322输出:
BWE说明:
首先按1,此时没有准备输出的字母,无效。
按两下2,准备输出'B'。
按一下1,将'B'输出。
再按一下1,无效。
按一下9,准备输出'W'。
按五下3,先将刚刚准备的''输出,然后准备输出'E'('D'->E'->'F'->'D'->'E').
按两下2,输出刚刚准备的'E',然后准备输出'B'。
没有后续输入,结束。纯暴力解法…… 内存空间应该还可以优化
#include <iostream>
using namespace std;
struct Nine_Button_Keyboard
{
Nine_Button_Keyboard()
{
for (int i = 0; i < 10; i++)
Button[i] = 0;
}
void Zero() //按键次数清零
{
for (int i = 0; i < 10; i++)
Button[i] = 0;
}
void OutPutWord() {
for (int i = 2; i < 10; i++) {
if (Button[i] > 0) {
if ((i != 7) && (i != 9)) {
cout << Word[i - 2][(Button[i]-1) % 3];
}
else {
cout << Word[i - 2][(Button[i]-1) % 4];
}
}
}
Zero();
}
int Button[10];
const char Word[8][4] = {
{'A','B','C'},
{'D','E','F'},
{'G','H','I'},
{'J','K','L'},
{'M','N','O'},
{'P','Q','R','S'},
{'T','U','V'},
{'W','X','Y','Z'}
};
};
class Solution
{
public:
void Nine_Button()
{
int PreButton = 1; //假设初始按键为1
struct Nine_Button_Keyboard NowButtons; //存储按键次数
char c;
while (cin >> c){
int NowButton = c - '0';
if ((PreButton != 1) && (NowButton != PreButton))
NowButtons.OutPutWord();
NowButtons.Button[NowButton]++;
PreButton = NowButton;
}
cout << endl;
}
};
int main() {
Solution().Nine_Button();
return 0;
}
}小红和小紫正在下一个名字叫"四子棋"的游戏。游戏的规则如下:
棋盘是一个n行m列的矩阵,两人轮流下子。如果有一方出现横、竖或者斜对角线方向有4个或4个以上的相同颜色的连珠,则获得游戏胜利。
小红拿到了棋局的终盘,她想知道是谁获得了胜利。
第一行输入两个正整数n和m,用空格隔开。
接下来的n行,每行输入一个长度为m的字符串,字符串仅由'r'、'p和'.'三种字符组成。'r'代表小红的棋子,'p'代表小紫的棋子,'.'代表未落子。
保证'x'和'p'的数量之差的统对值不超过1。
如果小红获胜,则输出"kou"
如果小紫获胜,则输出"yukari"
如果暂时无人获胜,则输出"to be continued"
输入:
4 5
rpprr
prrpp
p.r..
p..r.输出:
kou说明:
小红连成了一个对角线方向的四连珠。还是纯暴力解法…… 判断四种情况
#include<iostream>
#include<vector>
using namespace std;
void Judge(int rows, int cols, vector<vector<char>> Chess) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
int temp = Chess[i][j];
if (temp != '.') {
if (j + 3 < cols&&temp == Chess[i][j + 1] && temp == Chess[i][j + 2] && temp == Chess[i][j + 3]) {
if (temp == 'r')
cout << "kou" << endl;
else
cout << "yukari" << endl;
return;
}
else if (i + 3 < rows&&temp == Chess[i + 1][j] && temp == Chess[i + 2][j] && temp == Chess[i + 3][j]) {
if (temp == 'r')
cout << "kou" << endl;
else
cout << "yukari" << endl;
return;
}
else if (j + 3 < cols&&i + 3 < rows&&temp == Chess[i + 1][j + 1] && temp == Chess[i + 2][j + 2] && temp == Chess[i + 3][j + 3]) {
if (temp == 'r')
cout << "kou" << endl;
else
cout << "yukari" << endl;
return;
}
else if (j + 3 < cols&&i - 3 >= 0&&temp == Chess[i - 1][j + 1] && temp == Chess[i - 2][j + 2] && temp == Chess[i - 3][j + 3]) {
if (temp == 'r')
cout << "kou" << endl;
else
cout << "yukari" << endl;
return;
}
}
}
}
cout << "to be continued" << endl;
}
int main()
{
int n; cin >> n; cin.get();
int m; cin >> m; cin.get();
vector<vector<char>> Chess;
Chess.resize(n);
for (int i = 0; i < n; i++) {
//Chess[i].resize(m);
char c;
for (int j = 0; j < m; j++) {
cin >> c;
Chess[i].push_back(c);
}
}
Judge(n, m, Chess);
return 0;
}给出一棵有n个点,以1为根的树,点的标号为[1,n]。
点i有权值,每个点的价值定义为其子树的权值和。
求在所有无祖先后代关系的点对(x,y)中,x和y两点价值差值的最小值
如果不存在这样的点对,输出1000000000。
第一行输入一个整数n。
第二行输入n个整数,第i个整数表示;
接下来n-1行,每行两个整数x和y,表示有一条x指向y的边。
其中:
输出一行一个整数表示答案
输入:
4
1 1 3 2
1 2
1 3
3 4输出:
1说明:
4个点的价值为[7,1,5,2],其中点2和点4是无祖先后代关系并且差值最小的输入:
6
6 1 3 9 8 10
1 2
2 3
3 4
3 5
4 6输出:
2没看懂题……留给大佬来解答吧