Swea_1289
SWEA 1289번
Link: 1289번: 원재의 메모리 복구하기
문제 설명
무난하게 풀었던 구현 문제.
string 처리에서 살짝 헤맨것 말고는 무난하게 풀었다.
정답 코드
//
// Created by Keith_Lee on 07/01/2019.
//
#include <iostream>
#include <string.h>
using namespace std;
int T;
int main(){
cin >> T;
string input = "";
for(int test=1; test<=T; test++){
int count = 0;
string modified = "";
cin >> input;
for(int i=0; i<input.length(); i++){
modified.push_back('0');
}
for(int i=0; i<input.length(); i++){
if(modified[i] != input[i]){
if(input[i] == '0'){
for(int j=i; j<modified.length(); j++){
modified[j] = '0';
}
}
else if(input[i] == '1'){
for(int j=i; j<modified.length(); j++){
modified[j] = '1';
}
}
count++;
}
}
cout << '#' << test << ' ' << count << '\n';
}
return 0;
}