2015年1月23日 星期五

Tips of Code Blocks

Tips of Code Blocks

  1. You can create a duplicate of the line the caret is on, by pressing Ctrl+D 
  2. You can indent / unindent blocks of text using the TAB and SHIFT-TAB keys 
  3. You can press F2 and Shift-F2 to hide the messages and manager pane respectively 
  4. You can perform a quick search to Google, Google Code or MSDN by holding Ctrl and right-clicking the text you want to search 
  5. You can zoom in and out in the editor by holding Control while rolling the mousewheel 
  6. Undo last action Ctrl-Z 
  7. Redo last action Ctrl-Shift-Z 
  8. Auto-complete Ctrl-J

2015年1月15日 星期四

next_permutation

#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
   int a[] = {1,2,3,4,5,6,7,8};
   int n;
   while ( cin >> n)
   {
      do
      {
          for(int i=0; i<n; i++) cout << a[i];
          cout <<endl;
      } while ( next_permutation( a , a+n ) );
   }
}

Insert Sort III

#include <iostream>
using namespace std;
int a[6];
void printArray()
{
    for (int i=0;i<sizeof(a)/sizeof(*a);i++)
        cout << a[i]<<' ';
    cout <<endl;
}

int main()
{
  int b[6]={5,7,3,2,8,4};
  a[0]=b[0];
  for (int i=0;i<sizeof(a)/sizeof(*a);i++)
  {
    int t=b[i];
    int j;
    for (j=i-1;j>=0 && t<a[j]  ;j--)
         a[j+1]=a[j];
    a[j+1]=t;
  }
  printArray();
}

Insert Sort II

#include <iostream>

using namespace std;

int main()
{
    int b[8] = {5,2,8,7,3,6,9,1};
    int a[8];
    a[0]=b[0];
    int bsize = sizeof(a)/sizeof(a[0]);
    for (int i=1;i<bsize;i++)
    {
        int t=b[i];
        int j;
        for (j=i-1;j>=0 && t <a[j];j--)
              a[j+1]=a[j];
        a[j+1]=t;
    }
    for (int i=0;i<bsize;i++)
        cout <<a[i]<<' ';
    cout <<endl;
}

2015年1月14日 星期三

Insertion sort II

#include <iostream>
using namespace std;
int a[20];
void printArray(int a[],int n)
{
    for (int i=0;i<=n;i++)
        cout << a[i]<<' ';
    cout <<endl;
}

int main()
{
  int b[6]={5,7,3,2,8,4};

  int i=0;
  a[i]=b[i];
  printArray(a,i);
  i++;

  while (i<6)
  {
        int t = b[i];
        int j=i-1;
        while (t<a[j])
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=t;
        printArray(a,i);
        i++;
  }

}

Insertion Sort

#include <iostream>
using namespace std;

int  printArray(int a[],int n)
{
    for (int i=0;i<=n;i++)
        cout <<a[i]<<' ';
    cout << endl;
}

int main()
{
   int a[20];
   int t;
   cin >> t;
   int i=0;
   a[i] = t;
   while (cin >>t)
   {
       i++;
       int j;
       for (j=i;j>=0 && t<a[j];j--)
           a[j+1]=a[j];
       a[j+1]=t;
       printArray(a,i);
   }
}