Language/C++

[c++] 백준 외않되? 모음집

개ㅁI 2022. 7. 22. 23:42

<1110번>

#include <iostream>
using namespace std;

int main() {
	int A = 0, B = 0, C = 0, R;
	int I; 
	int N=0; 
	cin >> I;
	B = I % 10; 
	A = (I - B) / 10; 
	R = A + B; 
	while (R != C) {
		C = A + B;
		A = B;
		B = C % 10;
		C = A + B;
		N++;
	}
	if (I < 10) {
		cout << N + 1;
	}
	else
		cout << N;
	

	return 0;
}

 

 

<8958번>

cin>>score[num];에서 'score'에서 잘못된 데이터를 읽고 있습니다. 읽기 가능한 크기는 'num*1'바이트인데 실제로는 '2'바이트만 읽을 수 있습니다. 라고 뜸. 

#include <iostream>
using namespace std;

int main() {
	int length = 0;
	cin >> length;
	int num = 0;
	char* score = new char[num];
	int sum = 0;
	int continu = 0;

	for (int i = 0; i < length; i++) {
		while (true) {
			cin >> score[num];
			if (score[num] == 'O' || score[num] == 'X') {

				if (score[num] == 'O') {
					if (score[num] == score[num - 1]) {
						continu++;
						sum += continu;
					}
					else sum++;

				}
				num++;
				continu = 0;
			}

			else false;
		}
		cout << sum << endl;
	}
}

 

 

<4673번>

10의 자리까지는 맞게 나오는데 그 뒤에 마지막 1000의 자리에서 7이 차이가 남. 왜지? 잘 짰는데...

else if 말고 if로 쓰니까 됨. 10,100,1000이게 누락돼서 그런거 같기도..

#include <vector>
#include <iostream>

using namespace std;

int main()
{
	int dn[10000];
	int count[10000] = { 0 };


	for (int i = 0; i < 10000; i++) {
		if (i < 10) {
			dn[i] = i + i;
		}

		else if (10 < i < 100) {
			int first = i % 10;
			int second = (i - i % 10) / 10;

			dn[i] = i + first + second;
		}

		else if (100 < i < 1000) {
			int first = i % 10;
			int second = ((i % 100) - (i % 10)) / 10;
			int third = (i - i % 100) / 100;

			dn[i] = i + first + second + third;
		}

		else if (1000 < i < 10000) {
			int first = i % 10;
			int second = ((i % 100) - i % 10) / 10;
			int third = ((i % 1000) - i % 100) / 100;
			int fourth = (i - i % 1000) / 1000;

			dn[i] = i + first + second + third + fourth;
		}
	}

	for (int k = 0; k < 10000; k++) {
		for (int j = 0; j < 10000; j++) {
			if (j == dn[k]) {
				count[j]++;
			}
		}
	}

	for (int w = 0; w < 10000; w++) {
		if (count[w] == 0) {
			cout << w << endl;
		}
	}

}

 

<1065번>

어디서 틀린지 모르겠음. 

#include <iostream>
using namespace std;

int cnt = 0;
 
int one(int N)
{
	cnt = N;
	return cnt;
}

int ten(int N)
{
	cnt = 0;
	int N_second = (N - N % 10) / 10;

	for (int s = 0; s < N_second; s++) {
		cnt += 9;
	}
	for (int f = 0; f <= N % 10; f++) {
		cnt++;
	}

	return cnt;
}

int hundred(int N)
{
	cnt = 0;

	for (int i = 100; i < N; i++) {
		int i_frist = i % 10;
		int i_second = (i % 100 - i % 10) / 10;
		int i_third = (i - i % 100) / 100;

		if (i_second - i_third == i_frist - i_second && i_second-i_third != 0) {
			cnt++;
		}
	}

	return cnt;
}


int main()
{
	int N = 0;
	cin >> N;
	int count = 0;

	if (0 < N && N < 10) {
		count = one(N);
	}

	else if (10 <= N && N < 100) {
		count = ten(N);
	}

	else if (100 <= N && N <= 1000) {
		count = ten(100) + hundred(N);
	}

	cout << count;
}

 

<2675번>

심각도 코드 설명 프로젝트 파일 줄 비표시 오류(Suppression) 상태
오류 C3867 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::size': 비표준 구문입니다. '&'를 사용하여 멤버 포인터를 만드세요. 

라는 에러코드가 뜨는데 어떻게 해결해야 되는지 모르겠음. 

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

void Print(int num, string& s)
{
    for (int k = 0; k < s.length(); k++) {
        for (int i = 0; i < num; i++) {
            cout << s[k];
        }
    }
}

int main() {

    string s;
    int num;

    do{
        cin >> num >> s;
        Print(num, s);
        cout << endl;

    } while (s.size != 0);
    
    return 0;
}

 

<1152번>

이건 진짜 왜 안 되는지 이해가 안 됨. 정답 다 맞는데,,, 틀렸대,,, 어디서 틀렸는데???

#include <iostream>
#include <string>
using namespace std;

int main() {
	string str;
	getline(cin, str);
	int count = 1;

	for (int i = 0; i < str.length(); i++) {
		if (str[i] == ' ') {
			count++;
		}
	}
	cout << count;
}

 

<2941번>

왜왜왜오애??? 왜 안 돼?? 예제 실행시키면 다 맞게 나오는데?? 왜????

#include <iostream>
#include <string>
using namespace std;

int main() {
	string str;
	cin >> str;
	int count = 0;
	string kroatia;
	count = str.length();

	for (int i = 0; i < str.length(); i++) {
		kroatia = { str[i], str[i + 1] };

		if (kroatia == "c=") {
			count--;
		}
		if (kroatia == "c-") {
			count--;
		}
		if (kroatia == "d-") {
			count--;
		}
		if (kroatia == "lj") {
			count--;
		}
		if (kroatia == "nj") {
			count--;
		}
		if (kroatia == "s=") {
			count--;
		}
		if (str[i + 1] == 'z' && str[i + 2] == '=') {
			count--;
		}
		if (str[i] == 'd' && str[i + 1] == 'z' && str[i + 2] == '=') {
			count--;
		}
	}

	cout << count;
}

 

<1316 번>

진짜 킹받아 예시에 있는 거 다 맞게 도는데 틀렸대....

#include <iostream>
#include <string>
using namespace std;

int check(string words)
{
	int size = words.length();
	char different;
	int check = 1;

	for (int i = 0; i < size; i++) {
		
		if (words[i] != words[i + 1]) {
			different = words[i];
			
			for (int j = i+2; j < size-i; j++) {
				if (different == words[j]) {
					check = 0;
				}
			}
		}
	}

	return check;
}

int main() {
	int N;
	cin >> N;

	string words;
	int count = 0;

	for (int i = 0; i < N; i++) {
		cin >> words;
		count+=check(words);
	}

	cout << count;
}

 

<10757번> 

완벽한데.. 어디서 틀렸다는건지 모르겠음

#include <iostream>
#include <string>
using namespace std;
using std::to_string;

string default_b(string a, string b)
{
	int diff;
	string redefine_b;
	diff = a.size() - b.size();
	for (int i = 0; i < diff; i++) {
		redefine_b += "0";
	}
	redefine_b += b;

	return redefine_b;
}

string default_a(string a, string b)
{
	int diff;
	string redefine_a;
	diff = b.size() - a.size();
	for (int i = 0; i < diff; i++) {
		redefine_a += "0";
	}
	redefine_a += a;
	

	return redefine_a;
}

int main() {
	string a, b, result;
	int temp_r;
	int r, s = 0;
	cin >> a >> b;

	if (a.size() > b.size()) {
		b = default_b(a, b);
	}
	else if (a.size() < b.size()) {
		a = default_a(a, b);
	}

	for (int i = b.size(); i > 0; i--) {
		r = a[i-1]-'0' + b[i-1]-'0' + s;

		if (r < 10) {
			result += to_string(r);
			s = 0;
		}
		else {
			temp_r = r - (r / 10) * 10;
			result += to_string(temp_r);
			s = r / 10;
		}
	}
	if (s > 0) {
		result += to_string(s);
	}

	//cout << result << endl;

	for (int i = result.size(); i >= 0; i--) {
		cout << result[i];
	}
	

}

 

728x90