개발자 톡
코드 공유합니다. 지적해주실 부분 있으면 지적 부탁드립니다.
- 등록일
- 2024-03-22 14:35:35
- 조회수
- 269
- 작성자
- imim0523
#include<iostream>
#include<vector>
using namespace std;
class segment{
public:
segment(int num) : bit(vector<char>(8, 0)){
switch (num){
case 0: this->bit = {0, 0, 1, 1, 1, 1, 1, 1}; break;
case 1: this->bit = {0, 0, 0, 0, 0, 1, 1, 0}; break;
case 2: this->bit = {0, 1, 0, 1, 1, 0, 1, 1}; break;
case 3: this->bit = {0, 1, 0, 0, 1, 1, 1, 1}; break;
case 4: this->bit = {0, 1, 1, 0, 0, 1, 1, 0}; break;
case 5: this->bit = {0, 1, 1, 0, 1, 1, 0, 1}; break;
case 6: this->bit = {0, 1, 1, 1, 1, 1, 0, 1}; break;
case 7: this->bit = {0, 0, 1, 0, 0, 1, 1, 1}; break;
case 8: this->bit = {0, 1, 1, 1, 1, 1, 1, 1}; break;
case 9: this->bit = {0, 1, 1, 0, 1, 1, 1, 1}; break;
default: this->bit = {0, 0, 0, 0, 0, 0, 0, 0}; break;
}
}
int operator-(const segment & seg){
int cnt = 0;
for (int i = 0; i < 8; i++){
cnt += abs(this->bit[i] - seg.bit[i]);
}
return cnt;
}
private:
vector<char> bit;
};
class Button{
public:
Button(string start, string end){
this->start = Regularization(start);
this->end = Regularization(end);
this->click();
}
void click(){
this->count = 0;
for (int i = 0; i < 5; i++){
segment seg_e(this->end[i] - '0');
segment seg_s(this->start[i] - '0');
this->count += seg_e - seg_s;
}
}
string Regularization(string data){
int len = data.size();
for (int i = 0; i < 5 - len; i++){
data = '-' + data;
}
return data;
}
int Count() { return this->count; }
private:
string start;
string end;
int count;
};
int main(int argc, char** argv)
{
int N;
cin >> N;
for (int i = 0; i < N; i++){
string start, end;
cin >> start >> end;
Button click(start, end);
cout << click.Count() << endl;
}
return 0;
}