秋招笔试-清理IDE(三)

#pragma once

#include <unordered_map>
#include <crtdbg.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;

#if 0

void fun() {
cout << "--" <<1+3<< endl;
}


struct Node {
int val;
Node* next;
Node() {
next = nullptr;
val = 0;
}
Node(int val) {
next = nullptr;
this->val = val;
}

Node(int val, Node* node) {
this->val = val;
this->next = node;
}
};


int main() {
_CrtSetBreakAlloc(158);
cout << "*" << endl;
Node* node = new Node(10);

_CrtDumpMemoryLeaks();
return 0;
}

#endif

# if 0

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;

const int MAX = 1000;
char maza[MAX][MAX];//记录迷宫
int step[MAX][MAX];//记录步数
int sx, sy, ex, ey;//记录起点和终点

struct Point
{
int x;
int y;
} point1, point2;//记录当前位置和下一位置

int dir[4][2] = { { 0,1 },{ 0,-1 },{ -1,0 },{ 1,0 } };//上下左右四个方向

queue<Point> Q;//队列


int main()
{
int n, flag;
while (cin >> n)
{
flag = 0;
while (!Q.empty())
Q.pop();//清空队列
memset(step, 0, sizeof(step));//把记录步数的数组设为0

for (int i = 0; i<n; ++i)
scanf("%s", maza[i]);

for (int i = 0; i<n; ++i)
for (int j = 0; j<n; ++j)
{
if (maza[i][j] == 'S')
sx = i, sy = j;
if (maza[i][j] == 'E')
ex = i, ey = j;//遍历图形找到起点和终点
}

step[sx][sy] = 1;//设起点为1表示已经被访问过
point1.x = sx;
point1.y = sy;
Q.push(point1);//把起点添加到队列

while (!Q.empty())//当队列不为空时进行循环查找队列
{
point1 = Q.front();//拿出队列首元素
Q.pop();//拿出后移除首元素
for (int i = 0; i<4; ++i)
{
point2.x = point1.x + dir[i][0];
point2.y = point1.y + dir[i][1];
if (point2.x >= 0 && point2.y >= 0 && point2.x < n && point2.y < n && !step[point2.x][point2.y] && maza[point2.x][point2.y] != '#')
{
//如果下一个节点不出边界,没被访问过且不是墙,则步数+1
step[point2.x][point2.y] = step[point1.x][point1.y] + 1;
Q.push(point2);
}
}
if (step[ex][ey] != 0)
{//找到出口
flag = 1;
break;
}
}
if (flag)
cout << step[ex][ey] - 1 << endl;//因为起点为1,故需减去1则为步数
else
cout << -1 << endl;
}
return 0;
}

#endif


# if 0
// 保留两位小数
float a = 2.25755;

int main() {
float c = round(a * 100) / 100;
cout << c<<endl;
system("pause");
return 0;
}
#endif

#if 0

const int n = 8;
vector<string> graph(n,string(n,'.'));

vector<vector<string>> res;

bool isValid(vector<string>& g, int row, int col) {
for (int i = 0; i < g.size(); i++){
if (g[row][i]=='Q') {
return false;
}
}

for (int i = row-1, j = col - 1; i >= 0, j >= n; i--, j--) {
if (g[i][j] == 'Q')
return false;
}

for (int i = row - 1, j = col + 1; i >= 0, j >= n; i--, j++) {
if (g[i][j] == 'Q')
return false;
}

return true;
}

void dfs(vector<string>& g, int row) {

if (n == row) {
res.push_back(g);
return;
}

for (int col = 0; col < n; col++) {
if (isValid(g,row,col)) {
g[row][col] = 'Q';
dfs(g,row+1);
g[row][col] = '.';
}
}
}


int main() {
res.clear();
graph.clear();
cout << "start search"<<endl;
dfs(graph, 0);
cout << "result is :" << endl;
for_each(res[0].begin(), res[0].end(), [](string & s) { cout << s << endl; });

system("pause");

return 0;
}

#endif // 1

#if 0
#include "stdafx.h"
#include<iostream>
#include<vector>
#include <sstream>
using namespace std;
int main() {     int n;     cin >> n;     string s;     cin >> s;     istringstream sin(s);     string temp;     vector<int> inarr;     while (getline(sin, temp, ' ')) {         inarr.push_back(stoi(temp));     }     int q;     cin >> q;     vector<int> inarr2;     string str2;     cin >> str2;     istringstream sin2(str2);     while (getline(sin, temp, ' ')) {         inarr2.push_back(stoi(temp));     }     for (int& num : inarr2) {         int sum = 0;         for (int & nn : inarr2) {             sum += nn;         }         cout << sum;     }     return 0;


}

#endif


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务