2016年3月16日 星期三

因數、質數 AI2

2015年2月24日 星期二

Metaprogramming -- 程式製造程式

//參考資料來源 http://www.csie.ntnu.edu.tw/~u91029/Programming.html
//修為windows版

#include  <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()
{
    // 輸入四則運算式
    string s;
    cin >> s;

    // 製作程式碼
    ofstream fout("temp.cpp");
    fout << "#include <iostream>\n";
    fout << "using namespace std;\n";
    fout << "int main()\n";
    fout << "{\n";
    fout << "   cout << (" << s << ") << endl;\n";
    fout << "   return 0;\n";
    fout << "}\n";
    fout.close();

     // 編譯和執行(在windows底下)
    system("g++ temp.cpp -o temp.out");
     system("temp.out");

    // 刪除暫存檔案
    system("del temp.out");
    system("del temp.cpp");
}

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();
}