# ZeroJudge - f637: DF-expression ### 題目連結:https://zerojudge.tw/ShowProblem?problemid=f637 ###### tags: `ZeroJudge` `模擬` ```cpp= #include <iostream> #include <string> using namespace std; int nowAt, pixels; string DF; void DepthFirst(int nowLength) { nowLength >>= 1; for (int i = 0; i < 4; ++i) { ++nowAt; if (DF[nowAt] == '0') continue; if (DF[nowAt] == '1') { pixels += nowLength * nowLength; continue; } DepthFirst(nowLength); } } int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int length; cin >> DF >> length; nowAt = 0; if (DF[0] == '2') DepthFirst(length); else if (DF[0] == '1') pixels += length * length; cout << pixels << '\n'; } ```