Repository navigation
Expand file tree
/
Copy pathArray.cpp
More file actions
135 lines (125 loc) · 2.26 KB
/
Copy pathArray.cpp
File metadata and controls
135 lines (125 loc) · 2.26 KB
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
// Array.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
//有效的数独输入
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
for(int i = 0; i < 9; i++)
{
int row[9] = {};
int col[9] = {};
int cube[9] = {};
int temprow,tempcol,tempcube;
for(int j = 0; j < 9; j++)
{
//行
if(board[i][j] != '.')
{
temprow = board[j][i] - '1';
if(row[board[i][j] - '1'] == 1)
{
return false;
}
else
{
row[board[i][j] - '1'] = 1;
}
}
//列
if(board[j][i] != '.')
{
tempcol = board[j][i] - '1';
if(col[ board[j][i] - '1'] == 1)
{
return false;
}
else
{
col[ board[j][i] - '1'] = 1;
}
}
//宫
int x = 3*(i/3) + j/3;
int y = 3*(i%3) + j%3;
if(board[x][y] != '.')
{
tempcube = board[x][y] - '1';
if(cube[ board[x][y] - '1'] == 1)
{
return false;
}
else
{
cube[ board[x][y] - '1'] = 1;
}
}
}
}
return true;
}
};
//旋转矩阵
class Solution1 {
public:
void swap(int &left, int &right)
{
int temp = left;
left = right;
right = temp;
}
void rotate(vector<vector<int>>& matrix) {
int rowLen = matrix.size();
for(int i = 0; i < rowLen; i++)
{
for(int j = i+1; j < rowLen; j++ )
{
swap(matrix[i][j], matrix[j][i]);
}
}
int colLen = rowLen/2;
for(int i = 0; i < rowLen; i++)
{
for(int j = 0; j < colLen; j++)
{
swap(matrix[i][j], matrix[i][rowLen-j-1]);
}
}
}
};
void TestSolution1()
{
vector<vector<int>> num;
vector<int> temp;
int row1[] = { 1,1,1};
for (int i = 0; i < 3; i++)
{
temp.push_back(row1[i]);
}
num.push_back(temp);
temp.clear();
int row2[] = { 2,2,2};
for (int i = 0; i < 3; i++)
{
temp.push_back(row2[i]);
}
num.push_back(temp);
temp.clear();
int row3[] = {3,3,3};
for (int i = 0; i < 3; i++)
{
temp.push_back(row3[i]);
}
num.push_back(temp);
temp.clear();
Solution1().rotate(num);
//do something to see elements in num
}
int _tmain(int argc, _TCHAR* argv[])
{
TestSolution1();
return 0;
}