# 9.27网易互娱笔试题1,2题代码

## 第一题

#include<bits/stdc++.h>

using namespace std;

vector<vector<int>> prepare(int n)
{
vector<vector<int>> data(n, vector<int>(n, 0));

int left = 0, right = n-1;
int up = 0, down = n-1;

int cnt = 1;
int flag = 1;
while(cnt <= n*n)
{
if(flag % 2 == 1)
{

for(int k = left; k <= right; k++) {
data[up][k] = cnt++;
}
up++;

for(int k = up; k <= down; k++)
{
data[k][right] = cnt++;
}
right--;

for(int k = right; k >= left; k--)
{
data[down][k] = cnt++;
}
down--;

for(int k = down; k >= up; k--)
{
data[k][left] = cnt++;
}
left++;

flag ++;
}else
{
for(int k = up; k <= down; k++)
{
data[k][left] = cnt++;
}
left++;

for(int k = left; k <= right; k++)
{
data[down][k] = cnt++;
}
down--;

for(int k = down; k >= up; k--)
{
data[k][right] = cnt++;
}
right--;

for(int k= right; k >= left; k--)
{
data[up][k] = cnt++;
}
up++;

flag++;
}
}

return data;
}

int main()
{
int C;
cin >> C;

vector<vector<int>> res;
for(int i = 0; i < C; i++)
{
int n, m;
cin >> n >> m;
res = prepare(n);

for(int j = 0; j < m; j++)
{
int a, b;
cin >> a >> b;
cout << res[a][b];

if(j < m-1) cout <<endl;
}

if(i < C-1) cout << endl;
}

return 0;
}


## 第二题

1
10
open libc.so
open libm.so
open libdl.so
dup 2
dup2 0 2
close 0
query 1
query 2
query 3
open log.txt

0
1
2
3
open libm.so
open libc.so
open libdl.so
0

#include<bits/stdc++.h>

using namespace std;

//int curmin = 0;
unordered_map<int, string> ump;

int main()
{
int T;
cin >> T;
for(int i = 0; i < T; i++)
{
ump = unordered_map<int, string>();
//curmin = 0;

int num;
cin >> num;
getchar();

for(int j = 0; j < num; j++)
{
string str;
getline(cin, str);
//cout << str << endl;

if(str[0] == 'o')
{
string temp = str.substr(5, str.size()-5);
int flag;
for(flag = 0; flag < 1000000; flag++) {
break;
}
}

cout << flag << endl;
ump[flag] = temp;

}else if(str[0] == 'c')
{
string temp = str.substr(6, str.size() - 6);
int tempint = stoi(temp);

ump.erase(tempint);

}else if(str[0] == 'q')
{
string temp = str.substr(6, str.size() - 6);
int tempint = stoi(temp);
cout << ump[tempint] << endl;

}else if(str[0] == 'd')
{
if(str[3] == '2')
{
string temp = "";
int k = 5;
for(;k < str.size(); k++)
{
if(str[k] != ' ')
{
temp+= str[k];
}else
{
break;
}
}
int left = stoi(temp);

temp = "";
for(;k < str.size(); k++)
{

temp+= str[k];
}

int right = stoi(temp);

ump[right] = ump[left];

}else
{
string temp = str.substr(4, str.size() - 4);
int tempint = stoi(temp);
string file = ump[tempint];

int flag;
for(flag = 0; flag < 1000000; flag++) {
break;
}
}

cout << flag << endl;
ump[flag] = file;

}
}

}
}

return 0;
}

09-28 916

04-11 218
05-06 201
09-28 24
02-11 2324
09-27 546
10-15 313