返回列表 發帖

[作業] 指標 (六) - 陣列 2

本帖最後由 tonyh 於 2014-9-13 18:03 編輯

陣列指標 --> 存放陣列成員位址的變數
位址運算符號 & --> 取得變數位址
間接運算符號 * --> 取得參考位址內的值
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr=n;    //宣告指標 nPtr, 同時啟動該指標
  8.      cout<<*nPtr<<endl;
  9.      cout<<*(nPtr+2)<<endl;
  10.      cout<<*(nPtr+4)<<endl;
  11.      cout<<*nPtr<<endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int *nPtr=n;
  8.     cout<<*nPtr<<endl;
  9.     cout<<*(nPtr+2)<<endl;
  10.     cout<<*(nPtr+4)<<endl;
  11.     cout<<*nPtr<<endl;
  12.    
  13.     system("pause");   
  14.     return 0;
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr=n;   
  8.      cout<<*nPtr<<endl;
  9.      cout<<*(nPtr+2)<<endl;
  10.      cout<<*(nPtr+4)<<endl;
  11.      cout<<*nPtr<<endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int *nPtr;
  8.     nPtr=n;
  9.     cout<<*nPtr<<endl;
  10.     cout<<*(nPtr+2)<<endl;
  11.     cout<<*(nPtr+4)<<endl;
  12.     cout<<*n<<endl;
  13.     system("pause");  
  14.     return 0;        
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[] = {1,3,5,7,9};
  7.      int *nPtr = n;   
  8.      cout << *nPtr << endl;
  9.      cout << *(nPtr + 2) << endl;
  10.      cout << *(nPtr + 4) << endl;
  11.      cout << *nPtr << endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n[]={1,3,5,7,9};
  7.     int* nPtr=n;
  8.     cout<<*nPtr<<endl;
  9.     cout<<*(nPtr+2)<<endl;
  10.     cout<<*(nPtr+4)<<endl;
  11.     cout<<*nPtr<<endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr=n;    //宣告指標 nPtr, 同時啟動該指標
  8.      cout<<*nPtr<<endl;
  9.      cout<<*(nPtr+2)<<endl;
  10.      cout<<*(nPtr+4)<<endl;
  11.      cout<<*nPtr<<endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr=n;   
  8.      cout<<*nPtr<<endl;
  9.      cout<<*(nPtr+2)<<endl;
  10.      cout<<*(nPtr+4)<<endl;
  11.      cout<<*nPtr<<endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int n[]={1,3,5,7,9};
  7.      int *nPtr=n;         
  8.      cout<<*nPtr<<endl;
  9.      cout<<*(nPtr+2)<<endl;
  10.      cout<<*(nPtr+4)<<endl;
  11.      cout<<*nPtr<<endl;
  12.      system("pause");
  13.      return 0;
  14. }
複製代碼

TOP

  1. #include <bits/stdc++.h>

  2. using namespace std;
  3. int mod = 1000000007, n;
  4. vector <int> dp;
  5. vector <int> coin;
  6. vector <int> visited;

  7. int aa(int x)
  8. {
  9.     if(visited[x])   return dp[x];
  10.     for(int i=0; i<n; i++)
  11.     {
  12.         if(coin[i]<=x)
  13.         {
  14.             dp[x] += aa(x-coin[i]);
  15.             dp[x]%=mod;
  16.         }
  17.     }
  18.     //cout << x << " " << dp[x] << endl;
  19.     visited[x]++;
  20.     return dp[x];
  21. }

  22. int main()
  23. {
  24.     /*
  25.     int x;
  26.     cin >> n >> x;
  27.     dp.resize(x);
  28.     visited.resize(x);
  29.     coin.resize(n);
  30.     dp[0]++;
  31.     visited[0]++;
  32.     for(int i=0; i<n; i++)
  33.         cin >> coin[i];
  34.     cout << aa(x);
  35.     return 0;
  36.     */
  37.     int n[] = {0, 1, 2, 3, 4, 5};
  38.     int *nptr = n;
  39.     cout << *nptr << endl;
  40.     nptr+=2;
  41.     cout << *nptr << endl;
  42.     nptr+=2;
  43.     cout << *nptr << endl;
  44. }
複製代碼

TOP

返回列表