顺时针打印矩阵
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example,
Given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
You should return [1,2,3,6,9,8,7,4,5].
题目意思是要将矩阵顺时针打印出来
- 在剑指offer中也有类似试题
解题思路以下:
视察矩形 以下 看成1个圈 上行 右列 下行 左列
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
矩形rows 行数为3 cols列数为3 行跟列都有1个范围 行数的范围为0到2 列数的范围为 0到2
设 rowstart=0 rowend=2 colstart=0 colend=2 分别辨识行的起始、结束 和列的起始和结束
打印先从第1行开始 也就是 1 2 3 开始 此时
行不变 行动rowstart 列的变化为 colstart 到 colend 也就是 0到2 number[rowstart][i] i表示列 打印完以后 rowstart ++ 表示行数往下扩大
接着打印当前 最右侧列 6 9
此时列不变成 colend 行变化 为 rowstart 到 rowend 打印完后 colend– 表示列变小
接着打印当前最下边行 8 7
同上,此时 行不变 列出 colend 变到colstart 打印完后 rowend 减小 往上走
接着打印 4
4为第1圈的最后1个边界 此时列不变 行从rowend到 rowstart 打印完后 colstart++ 列变大 往右走
上面为1个圈,接着循环就是,直到 rowstart > rowend 或 colstart > colend
代码以下:
class Solution {
public:
vector<int> spiralOrder(vector<vector<int> > &matrix) {
vector<int> result;
if(matrix.size()==0)
return result;
int m=matrix.size()⑴;
int n=matrix[0].size()⑴;
int sn=0;
int sm=0;
int i;
while(true)
{
for(i=sn;i<=n;i++)
result.push_back(matrix[sm][i]);
if(++sm>m)
break;
for(i=sm;i<=m;i++)
result.push_back(matrix[i][n]);
if(--n<sn)
break;
for(i=n;i>=sn;i--)
result.push_back(matrix[m][i]);
if(--m<sm)
break;
for(i=m;i>=sm;i--)
result.push_back(matrix[i][sn]);
if(++sn>n)
break;
}
return result;
}
};
带测试的代码
#include<iostream>
using namespace std;
void printMatrix(int number[3][4],int rows,int cols)
{
int rowstart=0;
int rowend=rows-1;
int colstart=0;
int colend=cols-1;
while(rowstart<=rowend&&colstart<=colend)
{
int i;
for( i=colstart;i<=colend;i++)
{
cout<<number[rowstart][i]<<" ";
}
++rowstart;
if(rowstart>rowend)
break;
for( i=rowstart;i<=rowend;i++)
{
cout<<number[i][colend]<<" ";
}
--colend;
if(colend<colstart)
break;
for( i=colend;i>=colstart;i--)
{
cout<<number[rowend][i]<<" ";
}
--rowend;
if(rowend<rowstart)
break;
for( i=rowend;i>=rowstart;i--)
{
cout<<number[i][colstart]<<" ";
}
++colstart;
if(colstart>colend)
break;
}
}
int main()
{
int number[3][4]={1,2,3,4,10,11,12,5,9,8,7,6};
printMatrix(number,3,4);
}
波比源码 » 顺时针打印矩阵
buy levaquin 250mg pills buy levofloxacin pills
avodart medication purchase tamsulosin sale order ondansetron for sale
buy spironolactone 100mg pill buy aldactone 100mg online cheap diflucan drug
order ampicillin 500mg pill ampicillin pill erythromycin for sale online
fildena order tamoxifen cost purchase methocarbamol without prescription
buy suhagra 100mg without prescription buy sildenafil 50mg for sale estradiol brand
lamictal generic purchase mebendazole generic retin gel drug
order tadalis online purchase avanafil generic buy voltaren 100mg pill
accutane pills buy zithromax 500mg pills order zithromax 250mg generic
cialis pill cialis 5 mg real viagra sites
order arimidex without prescription Low cost canadian viagra sildenafil 100mg sale
tadalafil 20mg kaufen tadalafil 5mg generika viagra kaufen
ramipril 10mg us ramipril 5mg price purchase azelastine online cheap
order hytrin 1mg pill arava 20mg us buy azulfidine 500 mg online
buy benicar 10mg for sale brand verapamil 240mg diamox 250mg over the counter
order isosorbide for sale buy telmisartan 80mg without prescription telmisartan cost
bupropion 150 mg cheap strattera 10mg oral order generic seroquel 50mg
salbutamol 100mcg ca levitra or viagra viagra sildenafil 50mg
tadalafil tablets order tadalafil for sale cheap symmetrel
naltrexone 50mg drug buy letrozole generic order aripiprazole for sale
purchase provera online cheap purchase microzide pills order cyproheptadine 4mg generic
fluvoxamine tablet order glipizide pill order glipizide 10mg
nootropil medication buy viagra 100mg pills real viagra sites
buy zithromax generic order prednisolone generic neurontin 100mg
order furosemide hydroxychloroquine drug purchase hydroxychloroquine pills
cialis brand generic anafranil 25mg anafranil 50mg brand
buy generic sporanox itraconazole brand tinidazole 300mg for sale
buy metformin 1000mg generic cialis 10mg cheap buy cialis 5mg online cheap
zyprexa online order purchase diovan for sale buy diovan for sale
buy norvasc 10mg online order sildenafil 100mg pill over the counter cialis
buy sildenafil 50mg online cheap lisinopril 10mg pill lisinopril 10mg for sale
prilosec without prescription online casino games online gambling casinos
help with essays real money games free welcome spins no deposit
research papers writing viagra 100mg order viagra 50mg pills
clomid for sale online ventolin generic red dog casino
order xenical online buy xenical 60mg without prescription zovirax 400mg generic
purchasing cialis on the internet female cialis pill order clopidogrel online cheap
allopurinol 100mg usa crestor for sale online order zetia 10mg online
order methotrexate online cheap order coumadin 2mg without prescription metoclopramide for sale online
order domperidone 10mg pill motilium over the counter cyclobenzaprine 15mg canada
oral flomax 0.2mg ondansetron 4mg us order aldactone 100mg online cheap
cialis from india order ampicillin 500mg buy ciprofloxacin 500mg generic
simvastatin over the counter buy valacyclovir 500mg proscar 5mg generic
flagyl 400mg over the counter buy augmentin 375mg sale purchase bactrim sale
purchase cephalexin for sale order cephalexin 250mg order erythromycin 500mg online cheap
buy tadalafil pills cialis 10mg usa buy viagra 100mg pill
viagra pills cost of cialis cialis tadalafil 5mg
cefuroxime 250mg sale methocarbamol cost methocarbamol price
casino online slots tadalafil tablets brand name cialis
research paper assistance research paper website where can i buy stromectol
online blackjack gambling live blackjack tadalafil 40mg us
oral zithromax 250mg neurontin 100mg tablet neurontin 800mg without prescription
furosemide 40mg canada cheap doxycycline 100mg plaquenil usa
brand fildena 50mg purchase rhinocort pill cheap budesonide
prednisone uk order prednisone generic order mebendazole 100mg generic
buy retin avana order order avanafil 100mg generic
clarithromycin 250mg tablet cheap catapres 0.1mg antivert 25 mg usa
order generic tiotropium bromide 9 mcg buy spiriva 9 mcg pills order terazosin 1mg pills
buy montelukast 10mg without prescription buy singulair 10mg buy sildenafil without prescription
order cialis online 10mg cialis play poker online for money
online money poker poker online for real money blackjack for money
best online blackjack world series of poker online blackjack for money
online casinos usa help writing essays pay for a research paper
ramipril drug order glimepiride sale purchase arcoxia pill
diamox 250mg without prescription acetazolamide 250 mg oral generic azathioprine 25mg
lanoxin 250mg pill telmisartan pills molnupiravir order
coreg without prescription ditropan 5mg generic generic elavil 10mg
purchase fosamax online order nitrofurantoin sale order motrin online cheap
dapoxetine pill avana 200mg for sale domperidone pills
order nortriptyline pills order pamelor 25 mg pill paroxetine 20mg usa
order indocin 50mg sale indocin 50mg pills generic cenforce 100mg
pepcid 40mg sale buy remeron 30mg generic mirtazapine 15mg sale
cheap doxycycline 200mg methylprednisolone 8 mg for sale medrol for sale online
buy nexium nexium 40mg cheap order lasix 40mg sale
generic cialis tadalafil woman us viagra
buy minocin 100mg without prescription minocycline 50mg pills cheap hytrin 5mg
cialis 40mg usa buying ed pills online best ed pills non prescription
glycomet pill glycomet cost tamoxifen 10mg generic
clomiphene 50mg canada prednisolone 20mg drug cheap prednisolone 40mg
prednisone 5mg generic buy amoxil 1000mg for sale amoxicillin 250mg sale
buy fildena 50mg pill proscar uk purchase proscar generic
ivermectin 3 mg over the counter order deltasone 20mg deltasone 40mg canada
modafinil over the counter modafinil 200mg over the counter metoprolol online buy
vibra-tabs over the counter order zovirax generic acyclovir pills
imuran online buy buy telmisartan 80mg online naproxen online buy
ditropan 5mg without prescription prograf brand brand trileptal
omnicef order online order lansoprazole for sale protonix oral
order generic zocor 20mg zocor usa sildalis generic
avlosulfon 100mg usa mesalamine for sale online purchase tenormin generic
Известно, что функции, выполняемые челюстями и
волосами на голове человека,
в значительной степени подверглись
отмиранию. Такая же участь грозит постигнуть и сексуальную жизнь человека в современной культуре.
Она уже оказала свое губительное воздействие
на половые отношения. Несмотря на то что
требования культуры далеко не всегда соблюдаются, и культурное сообщество закрывает глаза на нарушения установленных им требований.
Как вернуть интерес к жизни в любом возрасте
order uroxatral 10mg pill diltiazem drug order diltiazem 180mg pill
tadalafil 10mg canada best otc ed pills non prescription erection pills
tadalafil women cialis online without prescription sexual dysfunction
buy generic provigil online buy deltasone 10mg generic brand prednisone 10mg
buy generic amoxil online order prednisolone 5mg pill cheap prednisolone 40mg
purchase neurontin generic purchase gabapentin sale doxycycline pills
buy ventolin 4mg buy allergy pills onlin cheap levothroid sale
order serophene pills buy levitra 10mg pill purchase plaquenil pill
doxycycline 200mg us doxycycline 100mg pills amoxiclav over the counter
order generic synthroid 150mcg clomid cheap levitra 10mg over the counter
buy albenza pills for sale albenza for sale online order medroxyprogesterone 5mg online
glycomet 500mg cost metformin pills purchase norvasc online cheap
praziquantel 600mg brand biltricide over the counter buy cyproheptadine online
oral methotrexate 5mg methotrexate 10mg tablet purchase metoclopramide generic
cost imitrex 50mg purchase sumatriptan generic avodart 0.5mg sale
buy sumycin pill buy generic flexeril 15mg order lioresal generic
order toradol 10mg buy colchicine sale buy propranolol medication
clopidogrel oral generic fluvoxamine 100mg order ketoconazole online cheap
tamsulosin without prescription buy ondansetron online buy cheap generic aldactone
purchase duloxetine pill glipizide over the counter cheap nootropil
buy betnovate 20 gm creams buy betamethasone 20 gm without prescription buy itraconazole online cheap
order generic prometrium 100mg buy prometrium 200mg generic purchase zyprexa pills
order nateglinide 120 mg generic captopril 25mg uk where to buy atacand without a prescription
brand tegretol 400mg tegretol 400mg generic lincocin 500mg pill
cheap cialis generic cialis mail order overnight delivery viagra
diflucan 200mg usa diflucan 200mg us ciprofloxacin brand
estradiol order online order minipress 1mg for sale prazosin 1mg generic
order flagyl 400mg sale buy bactrim 960mg pills brand keflex 250mg
buy avanafil pill order avanafil 200mg generic buy generic cambia online
purchase indocin capsule cefixime online cheap cefixime 200mg
trimox canada biaxin 250mg ca biaxin 500mg price
minocin 50mg cost buy minocycline no prescription actos price
oral azipro 500mg buy prednisolone 10mg for sale cheap neurontin generic
lasix order buy antihistamine pills how to get albuterol without a prescription
cost vardenafil buy levitra 20mg sale buy hydroxychloroquine for sale
buy olmesartan pill cost divalproex 500mg buy depakote 500mg without prescription
carvedilol 6.25mg uk brand cenforce buy aralen medication
brand acetazolamide 250 mg cost imdur 40mg generic azathioprine
purchase olumiant generic where to buy olumiant without a prescription order generic atorvastatin
buy albuterol 100mcg online cheap buy pantoprazole 40mg generic buy phenazopyridine generic
oral singulair 5mg order dapsone 100mg online cheap buy cheap generic dapsone
buy norvasc 5mg online buy omeprazole sale prilosec 10mg sale
metoprolol 100mg drug order atenolol order medrol online cheap
buy diltiazem 180mg sale purchase zyloprim online order zyloprim for sale
buy acillin online ampicillin 250mg canada flagyl 200mg over the counter
sumycin 500mg us flexeril 15mg tablet purchase baclofen
oral trimethoprim cephalexin 125mg cost buy cheap cleocin
buy ketorolac medication colcrys pill propranolol drug
where can i buy reglan hyzaar medication esomeprazole 40mg us
buy cheap generic methocarbamol purchase suhagra pills purchase suhagra online cheap
buy avodart no prescription buy meloxicam without prescription buy cheap generic meloxicam
order aurogra online estradiol price estrace cost
proscar 5mg pills order viagra 100mg pills sildenafil overnight shipping
cialis 5mg drug cialis 40mg sale sildenafil for sale online
terbinafine cost order amoxicillin 250mg sale trimox 500mg brand
buy arimidex 1 mg pill clarithromycin usa order clonidine pills
divalproex 250mg without prescription diamox 250 mg cheap buy isosorbide paypal
buy imuran 25mg buy micardis 20mg sale telmisartan 80mg pills
erection pills viagra online tadalafil tablets tadalafil 40mg pills
phenazopyridine 200mg generic phenazopyridine cheap amantadine where to buy
buy hytrin 1mg generic order arava 10mg cost cialis 5mg
etoricoxib 60mg cheap purchase mesalamine online astelin 10ml sale
buy amiodarone 100mg pills buy amiodarone 200mg generic buy dilantin 100 mg online cheap
Provpn.info: vpn
buy macrodantin generic cheap furadantin 100 mg buy pamelor 25mg online
luvox 100mg without prescription order fluvoxamine 100mg without prescription order cymbalta online
order anacin for sale buy famotidine 40mg generic order pepcid 40mg sale
buy oxcarbazepine pills ursodiol online buy buy ursodiol 300mg online
buy decadron 0,5 mg online order nateglinide 120 mg generic buy starlix without prescription
ВЗР страхование: ВЗР страхование
captopril for sale order tegretol 200mg generic tegretol 200mg price
Завораживающее казино с интересной тематикой! На кэт казино регистрация заняла считанные минуты. Уровень безопасности впечатляет, а ассортимент игр порадовал. Очень доволен, это мой новый игровой дом
ciprofloxacin for sale buy lincocin generic order cefadroxil 500mg generic
buy combivir paypal generic retrovir quinapril pills
prozac 40mg for sale fluoxetine where to buy femara 2.5 mg cheap
buy frumil 5mg without prescription where can i buy clindac a buy acivir medication
buy zebeta bisoprolol drug terramycin 250 mg brand