Skip to content
Merged

Anu1 #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions decodeways.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Solution {
public:
int numDecodings(string s) {
/*int n = s.size();
int n1=0,n2=1,n3,ans;
for(int i=1;i<=n;i++){
n3=n1+n2;
n1=n2;
n2=n3;
}
cout<<n3<<endl;
for(int i=0; i<n; i++){
if(s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'){
if(s[n-1]=='3'||s[n-1]=='4'||s[n-1]=='5'||s[n-1]=='6'){
n3 = n3;
}
else{
n3=n3-2;
}
}
if(s[i]=='7'||s[i]=='8'||s[i]=='9'){
if(s[i-1]=='1')
n3=n3-2;
else
n3=n3-4;
}
ans = n3;
cout<<ans<<endl;
}
return ans;*/

if (!s.size() || s.front() == '0')
return 0;
int r1 = 1, r2 = 1;

for (int i = 1; i < s.size(); i++) {
if (s[i] == '0')
r1 = 0;
if (s[i - 1] == '1' || s[i - 1] == '2' && s[i] <= '6') {
r1 = r2 + r1;
r2 = r1 - r2;
}
else {
r2 = r1;
}
}

return r1;
}
};
Empty file added funny
Empty file.
42 changes: 42 additions & 0 deletions funnypermutation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);


int main()
{


int ttt;
cin>>ttt;
while(ttt--)
{
int n1;
cin>>n1;
if(n1==3)
cout<<"-1"<<endl;
else{
if(n1%2){
int anurag = (n1/2)+1;
for (int i = n1; i > anurag; i--)
{
cout<<i<<" ";
}
for (int i = 1; i <= anurag; i++)
{
cout<<i<<" ";
}
cout<<endl;

}
else{
for (int i = n1; i >= 1; i--)
{
cout<<i<<" ";
}
cout<<endl;
}
}
}
return 0;
}