bool range(double x_start, double x_end, double y_start, double y_end)
{
	if(x_start <= y_start && x_end <= y_end)
		return true;

	if (y_start <= x_start && y_end <= x_end)
		return true;

	return false;
}

x_start~x_end

y_start~y_end

사이 값 겹치는 값이 존재할 경우 true return;

                              없을 경우 true return;

int max_arr(int arr[], int arr_len) {
	int max, i;

	max = arr[0];

	for (i = 1; i < arr_len; i++) {
		if (max < arr[i])
			max = arr[i];
	}

	return max;
}

 

 

출처: new93helloworld.tistory.com/85

string lines[] = {"2016-09-15 01:00:04.001 2.0s", "2016-09-15 01:00:07.000 2s"};
int length = sizeof(lines) / sizeof(string);

- sizeof(문자열 배열)/sizeof(string)

출력 결과 : 2

#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
	string cities1[] = { "Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA" };

	int length = sizeof(cities1) / sizeof(string);

	for (int i = 0; i < length;i++)
		transform(cities1[i].begin(), cities1[i].end(), cities1[i].begin(), tolower);


	for (int i = 0; i < length;i++)
		cout << cities1[i] << endl;

	return 0;
}

 

 - algorithm의 transform()를 이용.

1. #include <algorithm> 추가

2. using namespace std; 추가

3. transform(문자열.begin(), 문자열.end(), 문자열.begin(), tolower);

 문자열 값이 소문자로 변경되어 해당 문자열에 입력된다.

 

#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
	string cities1[] = { "Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA" };

	int length = sizeof(cities1) / sizeof(string);

	for (int i = 0; i < length;i++)
		transform(cities1[i].begin(), cities1[i].end(), cities1[i].begin(), toupper);


	return 0;
}

 - algorithm의 transform()를 이용.

1. #include <algorithm> 추가

2. using namespace std; 추가

 - transform(문자열.begin(), 문자열.end(), 문자열.begin(), toupper);

 문자열 값이 대문자로 변경되어 해당 문자열에 입력된다.

 

 

 

#include <string>
using namespce std;
int main(void)
{
	string s="A";
    char lower = tolower(s);
    
    char upper = toupper(lower);
    
    return 0;
}

 

'Programming 언어 > C++' 카테고리의 다른 글

[C++] 정수 두 범위가 겹치는 지 확인  (0) 2020.11.25
[C++] 배열 최대값 구하기  (0) 2020.11.25
[C++] string 배열 수 세기  (0) 2020.11.25

+ Recent posts

1