Skip to content

6.4 Print Parenthesis with Left Parenthesis First

// 6.4_parenthesis.cpp : Defines the entry point for the console application.
//

#include <iostream>
using namespace std;
int i=0;
void parenthesis (int i,int j,char *a,int size)
{
if(i==0&&j==0)
{
::i++;

*(a+size-1) =”;
cout<<’(‘<<::i<<’)’<<a<<endl;
}
else if(i==0&&j!=0)
{
a[size-(i+j)-1] = ‘)’;
parenthesis(i,j-1,a,size);
}
else if(i!=0&&i<=j)
{
a[size-(i+j)-1] = ‘(‘;
parenthesis(i-1,j,a,size);
a[size-(i+j)-1] = ‘)’;
parenthesis(i,j-1,a,size);
}
}
int main()
{
char a[11]={};
parenthesis (5,5,a,11);
cout<<i;
}

CareerCup150(Edition 3) 14.1

// careercup14.1.cpp : Defines the entry point for the console application.
//

Given a matrix a[M][N] if any element in the array is 0.Every element in the same row and column will be set 0.
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;

void matrix_modify(int a[][5],int M,int N)//a[][] not recognized. Pitfall 1.
{
set < int > cols,rows;
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
if(a[i][j]==0)
{
cols.insert(j);
rows.insert(i);
}
set < int >::iterator iter = cols.begin();//pay attention to the :: pitfall 2
for(;iter!=cols.end();iter++)
for(int i=0;i<M;i++)
a[i][*iter] = 0;
for(iter = rows.begin();iter!=rows.end();iter++)//iter++,not rows++;need to pay attention to each word of code you write. pitfall3
for(int i=0;i<N;i++) a[*iter][i] = 0;
}
int main()
{
int a[4][5];
for(int i=0;i<4;i++)
{
for(int j=0;j<5;j++)
{
a[i][j] = (i+j)%5;
cout<<a[i][j];
}
cout<<endl;
}
a[0][0] = 100;
matrix_modify(a,4,5);
for(int i=0;i<4;i++)
for(int j=0;j<5;j++)
cout<<setw(6)<<a[i][j];
cout<<endl;

}

Hello world!

Welcome to WordPress.com. After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can always preview any post or edit it before you share it to the world.
Follow

Get every new post delivered to your Inbox.