rendered paste body#include<iostream>#include<vector>#include<algorithm>#include<string>#include<math.h>using namespace std;void prob5(int n);int main(){ // cout<<pow(3,30); prob5(2); // string ans=Add( getchar(); return 0;}////////////////////////string Add (string n1 , string n2){ string ans = ""; int t1 = n1.length() - 1; int t2 = n2.length() - 1; int c = 0 ; while (t1 < t2) { n1 = "0" + n1 ; t1 = n1.length() - 1; } while (t2 < t1) { n2 = "0" + n2 ; t2 = n2.length() - 1; } //cout<<n1<<" "<<n2; while (t1 >= 0 && t2 >= 0) { int a = n1[t1] - 48 ; int b = n2[t2] - 48 ; int t = a + b + c ; c = t / 10 ; t = t % 10 ; ans.push_back(t + 48); t1--; t2--; } if (c > 0) ans.push_back(c + 48); reverse (ans.begin() , ans.end()); return ans; }///////////////////////////////////void prob5(int n){ /* vector <long long> v(n); v[0]=1; long long count=1; for(int i=1;i<n;i++) { v[i]=(3*count); count*=3; } for(int i=0;i<n;i++) cout<<v[i]<<" "; */ string v[n]; for(int i=0;i<n;i++) v[i]='0'; // cout<<"hi"; for(int i=0;i<pow(3,n);i++) { // check(v); for(int j=n-1;j>=0||v[j]<"3";j--) { cout<<"hi"; if(v[j]=="3") { v[j]="0"; v[j -1] = Add (v[j - 1] , "1"); } } for(int k=0;k<n;k++) cout<<v[k]<<" "; cout<<endl; } }