---
# System prepended metadata

title: Week 12：位元運算、貪心

---

# Week 12：位元運算、貪心

:::info
時間：05/21 9:00 ~ 17:00
地點：成大資工系新館 **65304** 教室
主題：位元運算、貪心
直播連結：https://youtube.com/live/dGVl9neZnis?feature=share
:::

# 必作題題解

[TOC]

## 三章_第三節

### [TOJ 244 - Jessica的煩惱](https://toj.tfcis.org/oj/pro/244/)

撰寫者：Eason

雖然可以用 ASCII 直接實作
<font color=red>但這邊請用位元運算去做練習</font>

:::spoiler code
```cpp=
#include<bits/stdc++.h>
#define ll long long
#define weakson ios::sync_with_stdio(0), cin.tie(0);
using namespace std;

int main(){
    weakson;

    int n;
    cin >> n;

    string s;
    cin >> s;

    string ans;
    for (int i = 0; i < n; i++){
        if (s[i] & (1 << 5)) ans += s[i] & ~(1 << 5);
        else ans += s[i] | (1 << 5);
    }
    cout << ans << '\n';
    return 0;
}
```
:::

----

### [UVa 10469 - To Carry or not to Carry]()

撰寫者：Eason

作法觀察題目應該可以很快得知

:::spoiler code
```cpp=
#include<bits/stdc++.h>
#define ll long long
#define weakson ios::sync_with_stdio(0), cin.tie(0);
using namespace std;

int main(){
    int a, b;
    while (cin >> a >> b){
        cout << (a ^ b) << '\n';
    }
    return 0;
}
```
:::





