Given a number a, print the following pattern :
Input:
4
Output:
1111
1112
1122
1222
1223
1233
1234
Pls help. Last time when i posted the quesion, people told it was from contest. donno is still that contest is running.
Given a number a, print the following pattern :
Input:
4
Output:
1111
1112
1122
1222
1223
1233
1234
Pls help. Last time when i posted the quesion, people told it was from contest. donno is still that contest is running.
Why would you make a new topic for that? You could’ve continued the discussion in the old topic.
Can u send Sol. ?
void solve() {
int n;
cin >> n;
string level = string(n, '1');
cout << level << endl;
for(int i = 2; i <= n; i++) {
for(int j = n - 1; j >= i - 1; j--) {
level[j] = i + '0';
cout << level << endl;
}
}
}
Anee wrong for n>9 .
You are right. I assumed n < 10 and proceeded. Generalizing for any n might be hard.
U told u finded out the Sol. Pls share atleast now
Ok , my solution is too long , but wait here is updated @aneee004 's code
#define printvec(a) for(lli i=0;i<sz(a);i++) cout<<a[i]<<" "; cout<<endl;
void solve() {
int n;
cin >> n;
vector<int>level(n,1);
printvec(level);
for(int i = 2; i <= n; i++) {
for(int j = n - 1; j >= i - 1; j--) {
level[j] = i;
printvec(level);
}
}
}
Oh xD. That was all the modification that was required.
P.S: In your macro, you might not want to add a space after a[i]
?
Yes actually for more clearly visible I add space .
Yes thankz!