4.1數組

來源:互聯網
上載者:User

1.特殊的字元數組

2.不允許數組直接複製或賦值

...................

數組看了好多遍了. .. 寫幾個小程式

Code:
  1. //判斷兩個數組是否相等   
  2. #include <iostream>   
  3. using namespace std;   
  4. int main()   
  5. {   
  6.     int arr1[10];   
  7.     int arr2[10];   
  8.     cout << "input 10 numbers for array1: " << endl;   
  9.     for(size_t ix=0;ix<10;ix++)   
  10.     {   
  11.         cin >> arr1[ix];   
  12.     }   
  13.     cout << "input 10 numbers for array2: " << endl;   
  14.     for(size_t ix=0;ix<10;ix++)   
  15.     {   
  16.         cin >> arr2[ix];   
  17.     }   
  18.     for(size_t ix=0;ix<10;ix++)   
  19.     {   
  20.         if(arr1[ix]!=arr2[ix])   
  21.         {   
  22.             cout << "arr1 does not equals arr2." << endl;   
  23.             return 0;   
  24.         }   
  25.     }   
  26.     cout << "arr1 equals arr2~" << endl;   
  27. }  
Code:
  1. //判斷兩個數組是否相等   
  2. #include <iostream>   
  3. #include <vector>   
  4. using namespace std;   
  5. int main()   
  6. {   
  7.                      //用vector實現   
  8.     vector<int> ivec1;   
  9.     vector<int> ivec2;   
  10.     int readIn;   
  11.     cout << "input 10 numbers for vector1(-1 to exit):" << endl;   
  12.     cin >> readIn;   
  13.     while(readIn!=-1)   
  14.     {   
  15.         ivec1.push_back(readIn);   
  16.         cin >> readIn;   
  17.     }   
  18.     cout << "input 10 numbers for vector2:" << endl;   
  19.     cin >> readIn;   
  20.     while(readIn!=-1)   
  21.     {   
  22.         ivec2.push_back(readIn);   
  23.         cin >> readIn;   
  24.     }    
  25.     for(vector<int>::iterator iter1=ivec1.begin(),iter2=ivec2.begin();iter1!=ivec1.end();iter1++,iter2++)   
  26.     {   
  27.         if(*iter1 != *iter2)   
  28.         {   
  29.             cout << "vector1 does not equals vector2" << endl;   
  30.             return 0;   
  31.         }   
  32.     }   
  33.     cout << "vector1 equals vector2!";   
  34. }  

沒有考慮為空白的情況..

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.