답안 #319149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319149 2020-11-04T09:11:18 Z sofapuden 홀-짝 수열 (IZhO11_oddeven) C++14
0 / 100
1022 ms 504 KB
#include <bits/stdc++.h>

using namespace std;

string add(string a, string b){
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	while(a.size() < b.size()){
		a+='0';
	}
	while(b.size() < a.size()){
		b+='0';
	}
	int last = 0;
	for(int i = 0; i < (int)a.size(); ++i){
		int cur = a[i]+b[i]-2*'0' + last;
		last = cur/10;
		c+=(char)('0'+cur%10);
	}
	if(last){
		c+=(char)('0'+last);
	}
	reverse(c.begin(),c.end());
	return c;
}
string subs(string a, string b){
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	while(b.size() < a.size()){
		b+='0';
	}
	int last = 0;
	for(int i = 0; i < (int)a.size(); ++i){
		int cur = a[i]-b[i] + last;
		last = (cur-10)/10;
		c+=(char)('0'+((cur+10)%10));
	}
	while(c.back() == '0')c.pop_back();
	reverse(c.begin(),c.end());
	return c;
}

bool gre(string a, string b){
	if(a.size() > b.size()){
		return true;
	}
	if(b.size() > a.size()){
		return false;
	}
	return a >= b;
}
	

int main(){
	string a; cin >> a;
	string cn = "1";
	string cur = "1";
	while(!gre(cur,a)){
		cn = add(cn,"1");
		cur = add(cur,cn);
	}
	cout << subs(add(a,a),cn);
		
	
			
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Incorrect 1022 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -