Thursday, 6 February 2014

Playing with zeroes in matrices

It is one of the simplest tasks in C++. If an element in a matrix is found to be zero, then make its corresponding row and column to zeroes. Here is the code for the above task.

  1 #include<iostream> 
  2 using namespace std;
  3 class matrix 
  4 { 
  5     int a[50][50]; 
  6     int n,m; 
  7 public: 
  8     matrix(int rows,int cols) 
  9     { 
 10         n=cols; 
 11         m=rows; 
 12         **a=0; 
 13     } 
 14     void create() 
 15     { 
 16         cout<<"Enter elements: "; 
 17         for(int i=0;i<m;i++) 
 18         { 
 19             for(int j=0;j<n;j++) 
 20             { 
 21                 cin>>a[i][j]; 
 22             } 
 23         } 
 24     } 
 25     void zero() 
 26     { 
 27         int *rows=new int[m]; 
 28         int *cols=new int[n]; 
 29          
 30         for(int i=0;i<m;i++) 
 31         { 
 32             for(int j=0;j<n;j++) 
 33             { 
 34                 if(a[i][j]==0) 
 35                 { 
 36                     rows[i]=1; 
 37                     cols[j]=1; 
 38                 } 
 39             }                 
 40                      
 41         } 
 42      
 43         for(int i=0;i<m;i++) 
 44         { 
 45             for(int j=0;j<n;j++) 
 46             { 
 47                 if(rows[i]==1||cols[j]==1) 
 48                     a[i][j]=0; 
 49             } 
 50         } 
 51     } 
 52     void display() 
 53     { 
 54         for(int i=0;i<m;i++) 
 55         { 
 56             for(int j=0;j<n;j++) 
 57             { 
 58                 cout<<a[i][j]<<" "; 
 59             } 
 60             cout<<endl; 
 61         } 
 62     } 
 63  
 64 }; 
 65 int main() 
 66 { 
 67     int x,y; 
 68     cout<<"Enter rows and cols: "; 
 69     cin>>x>>y; 
 70     matrix m(x,y); 
 71     m.create(); 
 72     m.zero(); 
 73     cout<<"\nAfter change:\n"; 
 74     m.display(); 
 75     return 0;
 76 }
If there are any suggestions, please feel free to comment........See you again with a new challenge 

Sunday, 2 February 2014

Top 5 Launchers of 2013

Here are the top 5 Android Launchers for 2013 in ascending order. Download them in Google Play store and make your phone trendy and on par with modern world!!

#5 Smart Launcher:



 Smart Launcher is an innovative launcher characterized by a minimalist design, low memory usage and an user-friendly UI that let you start any application with a few taps.
 It has some of the following benefits:
  1. Main screen with quick start
  2. Ready to use without much configurations
  3. Support Live wallpapers for different sizes
  4. Fast search
  5. Landscape mode
  6. Easy access to app's info

#4 Bazooka Launcher:

Bazooka is based on Cyanogen’s Trebuchet Launcher — which comes stock with modern CyanogenMod ROMs.

Benefits:

  1. Fast and stable
  2. You can quickly download and apply themes
  3. Gesture support
  4. Fancy lock screen 








#3 Ez Launcher:


It is a cool launcher app which makes convenient to operate and organize your phone

Benefits:

  1. Genius app lets you access the most frequently visited apps.
  2. It automatically categorizes your apps
  3. Quick search is enabled to search your app easily
  4. Pre-loaded app manager tool
  5. Useful and handy widgets 




#2 Action Launcher:


Benefits:

  1. A sliding quick drawer for instant access of all your apps.
  2. Translucent navigation and status bar
  3. Quick search which allows to search apps and music directly from action bar.
  4. Strong play store integration.
  5. Full Tablet support
  6. Icon pack and Icon scaling support.

#1 Next launcher 3D:


Next Launcher 3D gives you a new experience of 3D vision pushing back traditional flat launcher.

Benefits:

  1. Fancy 3D effects with smooth experience.
  2. 3D transitions of home screens.
  3. Mind blowing and stunning 3D screen preview
  4. Build unique icon style by changing  size,angle, and location of that icon
  5. Shinny border experience for screen transitions
  6. Floating mode of icons.
Here is a video regarding these launchers:

Saturday, 1 February 2014

Check whether two strings are anagrams or not in c++

Here's the code to check if two strings are anagrams to each other or not...But I personally feel this could be more efficient. So please do comment if you find efficient solution. This program works for every test cases.

  1 #include<iostream> 
  2 using namespace std;
  3 bool anagram(char*,char*); 
  4 int main() 
  5 { 
  6     char s1[100],s2[100];
  7     cout<<"Enter string 1: "; 
  8     gets(s1); 
  9     cout<<"Enter string 2: "; 
 10     gets(s2); 
 11     if(anagram(s1,s2)) 
 12     { 
 13         cout<<"The two strings are anagrams! "; 
 14     } 
 15     else 
 16     { 
 17         cout<<"The two strings are not anagrams! "; 
 18     } 
 19     return 0;
 20 } 
 21 bool anagram(char*s,char*t) 
 22 { 
 23     int l1=strlen(s); 
 24     int l2=strlen(t); 
 25     if(l1!=l2) 
 26         return false; 
 27     int count1[256]={0},i,count2[256]={0}; 
 28     for(i=0;s[i]&&t[i];i++) 
 29     { 
 30         count1[s[i]]++; 
 31         count2[t[i]]++; 
 32     } 
 33     for(i=0;i<256;i++) 
 34     { 
 35         if(count1[i]!=count2[i]) 
 36             return false; 
 37     } 
 38     return true; 
 39 } 
 

Thursday, 30 January 2014

Find your Lost Android Phone

A lost phone is worrisome. You would fear that someone misuse your phone pushing you in serious troubles. I'm not talking about SIM, because you can block that. But what if you have very vital information stored in your phone??! Then definitely it is a serious issue. Prevention is better than cure. First of all implement the following steps:

  1. Go to Settings->Security->Device Administrators->Android Device Manager
  2. Tap on it and activate it.
  • Now if your phone is lost, go to google play store. 
  • There you can see a gear like button on the top right corner of your page, click on it and select Android Device Manger
You have 3 options:

  • Ring: You can ring your phone
  • Lock your phone
  • Erase all data: This will erase all data but not SD card. Also  Android Device Manger wont work if you erase the data


  • Tuesday, 28 January 2014

    Replace spaces in a string with %20

    Here's the code to replace all the spaces with %20 in a given string.

      1 #include<iostream> 
      2 using namespace std;
      3 int main() 
      4 { 
      5     int i,len,count=0; 
      6     char *str; 
      7     str=new char[100]; 
      8     cout<<"Enter your string: "; 
      9     gets(str); 
     10     len=strlen(str); 
     11     for(i=0;i<len;i++) 
     12     { 
     13         if(str[i]==' ') 
     14             count++; 
     15     } 
     16     int newlength=len+count*2; 
     17     str[newlength]='\0'; 
     18     for(i=len-1;i>=0;i--) 
     19     { 
     20         if(str[i]==' ') 
     21         { 
     22             str[newlength-1]='0'; 
     23             str[newlength-2]='2'; 
     24             str[newlength-3]='%'; 
     25             newlength=newlength-3; 
     26         } 
     27         else 
     28         { 
     29             str[newlength-1]=str[i]; 
     30             newlength=newlength-1; 
     31         } 
     32     } 
     33     cout<<"String after replacing: "; 
     34     puts(str); 
     35     return 0;
     36 } 

    Removing duplicates from the string

    Here's the code to remove duplicates from a given string. In this program, I've used a variable called tail which is used to remove all the duplicates and also acts as boundary for string comparison.


      1 #include<iostream> 
      2 using namespace std;
      3 int main() 
      4 { 
      5     char *str; 
      6     str=new char[50]; 
      7     cout<<"enter"; 
      8     cin>>str; 
      9     int tail = 1,len;
     10     len=strlen(str); 
     11      for (int i = 1; i < len; ++i) {
     12         int j; 
     13         for (j = 0; j < tail; ++j) {
     14              if (str[i] == str[j]) break;
     15          } 
     16         if (j == tail) { 
     17             str[tail] = str[i]; 
     18             ++tail; 
     19          } 
     20     } 
     21  str[tail] = 0; 
     22  for(int i=0;i<len;i++) 
     23      cout<<str[i]; 
     24  return 0;
     25 }
    I appreciate your suggestions if any....Thank you

    Reverse a String

    Here's a program to reverse a string. Although I'm not sure about the time complexity, this program has worked well

      1 #include<iostream> 
      2 using namespace std;
      3 int main() 
      4 { 
      5     char *a, *b,c; 
      6     int i,j; 
      7     cout<<"Enter: "; 
      8     a=new char[50]; 
      9     b=new char[50]; 
     10     cin>>a; 
     11     int l=strlen(a); 
     12      
     13     for(i=0,j=l-1;i<l-1,j>0,i<j;i++,j--) //Swap last and first characters
     14     { 
     15         c=a[i]; 
     16         a[i]=a[j]; 
     17         a[j]=c; 
     18     } 
     19     for(i=0;i<l;i++) 
     20         cout<<a[i]; 
     21     return 0;
     22 }