int i;
string s;輸入一串數字,然後將這串數字倒著輸出去?
ex: 1 2 3 -> 3 2 1
int a[5];
int a[5] = {1, 2, 3, 5, 6};
int a[] = {3, 4, 5};陣列宣告
陣列使用
cout << a[0] <<"\n";
cout << a[1] <<"\n";
cout << a[2] <<"\n";
a[0] = 6;int a[5] = {3, 6, 4, 5, 1};
for(int i = 0; i < 5; i++)
cout << a[i] <<" ";陣列:一次allocate 5個連續空間
a[0] = 7;//a[index] = value;| idx | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| val | 3 | 6 | 4 | 5 | 1 |
Remark: index從0到n - 1, n 為allocate的個數
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s[3];
for(int i = 0; i < 3; i++)
cin >> s[i];
for(int i = 2; i > -1; i--)
cout << s[i] << "\n";
return 0;
} 如果變數沒有初始值,那初始值可能是任意值
#include <iostream>
using namespace std;
int main()
{
int a[10];
for(int i = 0; i < 10; i++)
cout << a[i] <<"\n";
return 0;
}
想要讓陣列的所有初始值為 0 ?
#include <iostream>
using namespace std;
int main()
{
int a[5] = {0, 0, 0, 0, 0};
for(int i = 0; i < 5; i++)
cout << a[i] << "\n";
int b[5] = {};
for(int i = 0; i < 5; i++)
cout << b[i] << "\n";
return 0;
}
//syntax int a[Row][COL]
int main(){
int arr[2][3] = {
{9, 8, 7},
{6, 5, 4}
};
return 0;
}| [0][0]: 9 | [0][1]: 8 | [0][2]: 7 |
|---|---|---|
| [1][0]: 6 | [1][1]: 5 | [1][2]: 4 |
前面負責控制row,後面負責控制column
練習:zerojudge a015. 矩陣的翻轉(有很多組)
練習:zerojudge d481. 矩陣乘法
常見進位制
當數字達到一定數量(基數base)時,就向前一位進一
3小時26分鐘又10秒總共有幾秒?
個位數代表: 1
十位數代表:10個1也就是10
百位數代表:10個10也就是100
千位數代表:10個100也就是1000
1秒代表: 1
1分鐘:60個1秒也就是60秒
1小時:60分鐘也就是60*60秒
右一位數代表: 1
右二代表:8個1也就是8
右三位數代表:8個8也就是64
右四位數代表:8個64也就是512
每一位只能用一個字來代替
A: 10 D:13
B: 11 E:14
C: 12 F:15
請問
49會出現在8進位嗎,該如何表示
| 1 | 1 |
|---|---|
| 2 | 10 |
| 3 | 11 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
問題: 要把10進位轉成16進位,用長除法 ?
| n⁴ | n³ | n² | n | 1 |
|---|---|---|---|---|
| a | b | c | d | e |
進位制 基底可使用的符號
| 二進位 | 2 | 0, 1 |
| 八進位 | 8 | 0 ~ 7 |
| 十進位 | 10 | 0 ~ 9 |
| 十六進位 | 16 | 0 ~ 9, A~F(A=10...F=15) |