Last active
December 19, 2015 23:28
-
-
Save yonghanjung/6034484 to your computer and use it in GitHub Desktop.
Try-Catch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* MY code, solving the Try_catch problem */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <ctime> | |
#include <vector> | |
#include <algorithm> | |
#include <cstring> | |
#include <cstdio> | |
#include <cstdlib> | |
using namespace std; | |
long long primecheck(long long x){ | |
long long count = 0; | |
for (long long int i=2; i<=x; i++){ | |
if (x%i == 0) count ++; | |
} | |
if (count > 1){ | |
count = 0; | |
return -1; | |
} | |
else if (count == 1){ | |
count = 0; | |
return x; | |
} | |
} | |
int main(){ | |
long long factor = 600851475143 ; | |
vector<long long> str; | |
long long check; | |
for (long long int i = 2; i<sqrt(factor); i++){ | |
if (factor%i == 0){ | |
if( primecheck(factor/i) != -1){ | |
str.push_back((factor/i)); | |
} | |
else if (primecheck(i) != -1) { | |
str.push_back(i); | |
} | |
} | |
} | |
cout << str[str.size()-1]; | |
return 0; | |
} | |
/* Code Review | |
It wakes slowly, which means that it is written inefficiently | |
To correct that, I should know how to reduce the given number and the number of calculation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
bool number (int x){ | |
if (x = '0' || '1' || '2' || '3' || '4' || '5' || '6' || '7' || '8' | |
|| '9' || '0') | |
return true; | |
else return false; | |
} | |
int calc (int x, int y, char sign){ | |
switch(sign){ | |
case '+' : return x+y; | |
case '-' : return x-y; | |
case '/' : return x/y; | |
case '*' : return x*y; | |
} | |
} | |
int main(){ | |
char *input; | |
vector<char>vt; | |
char str[500]; | |
const int size = 500; | |
input = (char*)malloc(sizeof(char)*size); | |
fgets(input,sizeof(char)* size, stdin); | |
char *num = (char*)malloc(sizeof(char)*size); | |
for (int i = 0; i<strlen(input); i++){ | |
if(input[i] == '+' || input[i] == '-' || | |
input[i] == '*' || input[i] == '/'){ | |
vt.push_back(input[i]); | |
num[i] = ','; | |
} | |
if (input[i] == '0'|| input[i] == '1' || input[i] == '2' || input[i] == '3' || | |
input[i] == '4' || input[i] == '5' || input[i] == '6' || input[i] == '7' || | |
input[i] == '8' || input[i] == '9'){ | |
num[i] = input[i]; | |
} | |
} | |
vector<int>number; | |
char *cut = strtok(num,","); | |
do{ | |
number.push_back(atoi(cut)); | |
}while( (cut = strtok(NULL,",")) != NULL ); | |
number.push_back(0); | |
/* | |
vt stored sign | |
number stored number | |
*/ | |
int sum = 0; | |
sum = calc(number[0], number[1], vt[0]); | |
cout << "The value of sign :"; | |
for (int i = 0; i<vt.size(); i++){ | |
cout << vt[i]; | |
} | |
cout << endl; | |
cout << "The value of number :"; | |
for (int i = 0; i<number.size(); i++){ | |
cout << number[i]; | |
} | |
cout << endl; | |
for (int i =2; i<number.size(); i++){ | |
sum = calc(sum,number[i],vt[i-1]); | |
if (number[i+1] == 0) break; | |
} | |
cout << sum; | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int factorial(int num){ | |
int ans = num; | |
if (num != 1){ | |
ans = num*factorial(num-1); | |
} | |
if (num == 1){ | |
return ans; | |
} | |
} | |
// 팩토리얼 함수 | |
int main(){ | |
srand (time(NULL)); | |
const int size = 1000; | |
char *input; | |
input = (char*)malloc(size*sizeof(char)); | |
vector<char>vt; | |
vector<char>zero; | |
vector<char>one; | |
cin >> input; | |
cout << endl; | |
// | |
for(int i = 0; i<strlen(input); i++){ | |
vt.push_back(input[i]); | |
if (input[i] == '0') { | |
zero.push_back(input[i]); | |
} | |
else one.push_back(input[i]); | |
} | |
sort(vt.begin(), vt.end()); | |
int numzero = zero.size(); | |
int numone = one.size(); | |
/*for(int i = 0; i<vt.size(); i++){ | |
cout << vt[i]; | |
} | |
cout << endl; | |
for(int i = 0; i<zero.size(); i++){ | |
cout << zero[i]; | |
} | |
cout << endl; | |
for(int i = 0; i<one.size(); i++){ | |
cout << one[i]; | |
}*/ | |
// cout << vt[numzero-1]; | |
int iter = 0; | |
int itermax = (factorial(vt.size())) / (factorial(one.size()) * factorial(zero.size())); | |
char answer[itermax][vt.size()]; | |
int match = 0; | |
while(iter < itermax){ | |
random_shuffle(vt.begin(),vt.end()); | |
for (int i = 0; i<iter; i++){ | |
match = 0; | |
for (int j = 0; j<vt.size(); j++){ | |
if (answer[i][j] == vt[j]) match ++; | |
} | |
if (match == vt.size()){ | |
random_shuffle(vt.begin(),vt.end()); | |
i = i-1; | |
} | |
} | |
for (int i = 0; i<vt.size(); i++){ | |
answer[iter][i] = vt[i]; | |
cout << vt[i]; | |
} | |
cout << endl; | |
iter++; | |
} | |
// | |
/* for (int i = 0; i<itermax; i++){ | |
for (int j = 0; j<vt.size(); j++){ | |
cout << answer[i][j]; | |
} | |
cout << endl; | |
}*/ | |
// | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int main(){ | |
int row,col; | |
cin >> row >> col; | |
// 행렬의 크기를 입력받는다. | |
int input[row][col]; | |
// | |
for(int i=0; i<row; i++){ | |
for(int j=0; j<col; j++){ | |
cin >> input[i][j]; | |
} | |
} | |
// 행렬을 입력받는다. | |
vector<int>row_vt; | |
vector<int>col_vt; | |
for(int i=0; i<row; i++){ | |
for(int j=0; j<col; j++){ | |
if (input[i][j] == 1){ | |
row_vt.push_back(i+1); | |
col_vt.push_back(j+1); | |
} | |
} | |
} | |
// | |
int connect = 0; int prev_connect = 0; | |
int bunchcount = 0; | |
for (int i = 0; i<row_vt.size(); i++){ | |
prev_connect = connect; | |
connect = 0; | |
for (int j = 1; j<row_vt.size(); j++){ | |
if( ((row_vt[i] == row_vt[j]) && col_vt[j] == col_vt[i]+1 ) | |
|| | |
((col_vt[i] == col_vt[j]) && row_vt[j] == row_vt[i]+1 ) | |
){ | |
connect = 1; | |
} | |
} | |
if (prev_connect - connect >0 ) bunchcount ++; // 알고리듬의 핵심! | |
} | |
cout << bunchcount; | |
// | |
/*cout<<endl; | |
for (int i = 0; i<row_vt.size(); i++){ | |
cout << row_vt[i] << "," << col_vt[i] << endl; | |
}*/ | |
// | |
cout << endl; | |
return 0; | |
} | |
/* | |
위 프로그램의 알고리듬의 핵심은, | |
Disconnected 되어 있는 순간에 Bunch의 갯수를 Count 한다는 것이다. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int main(){ | |
char *input; | |
const int size = 500; | |
input = (char*)malloc(sizeof(char)*size); | |
fgets(input,sizeof(char)*size, stdin); | |
vector<int>vt; | |
vector<int>ans; | |
char *cut = strtok(input," "); | |
do{ | |
vt.push_back(atoi(cut)); | |
}while( (cut = strtok(NULL," ")) != NULL ); | |
sort(vt.begin(), vt.end()); | |
/* for (int i = 0 ; i< vt.size(); i++){ | |
cout << vt[i] << " "; | |
} | |
cout << endl; */ | |
int max = 0; | |
int match = 0; | |
int irem = 0; | |
int imax = 0; | |
for(int i = 0; i<vt.size(); i++){ | |
match = 0; irem = i; | |
for(int j = i+1; j<vt.size(); j++){ | |
if(vt[j] == vt[i] + 1){ | |
ans.push_back(vt[i]); | |
i++; match++; | |
if(match >= max) { | |
max = match; | |
imax = irem; | |
} | |
if(vt[j+1] != vt[j]+1){ | |
ans.push_back(vt[j]); | |
} | |
} | |
} | |
} | |
for (int i = 0 ; i<max+1; i++){ | |
cout << ans[imax++] << " "; | |
} | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Review | |
The point for this code is that of "i++, j++" at them same time. | |
At the same to calc. the number of rooping when printing, I used the maxmatch commander. | |
To remember the location, I attached the condition of the roop was contributing to maxmatch. | |
finally, I used vector to remember. | |
Another important technique that I want to emphasize was | |
string input; | |
getline(cin, input); | |
*/ | |
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
using namespace std; | |
int main(){ | |
do{ | |
string input; | |
getline(cin,input); // This is worth to be learend | |
vector<char>copy1; | |
vector<char>copy2; | |
vector<int>istr; | |
for (int i = 0; i < input.size(); i++){ | |
copy1.push_back(input[i]); | |
cout << copy1[i] << " "; | |
} | |
cout << endl; | |
for (int i=input.size()-1; i>=0; i--){ | |
copy2.push_back(input[i]); | |
} | |
for (int i = 0; i < input.size(); i++){ | |
cout << copy2[i] << " "; | |
} | |
cout << endl; | |
int match, | |
iremember, | |
maxmatch = 0; | |
for (int i = 0; i<copy1.size(); i++ ){ | |
match = 0; | |
iremember = i; | |
for (int j = 0; j<copy2.size() ; j++ ){ | |
if (copy1[i] == copy2[j]){ | |
i++; | |
match ++ ; | |
if (match > maxmatch){ | |
maxmatch = match; | |
istr.push_back(iremember); | |
} | |
continue; | |
} | |
} | |
} | |
cout << "maxmatch? " << maxmatch << endl; | |
cout << "istr? "; | |
for (int i = 0; i < istr.size(); i++){ | |
cout << istr[i] << " "; | |
} | |
cout << endl; | |
cout << "istr size? " << istr.size() << endl; | |
int start = istr[istr.size() -1]; cout << "start? " << start << endl; | |
cout << "Answer: "; | |
for (int i = 0; i<maxmatch; i++){ | |
cout << copy1[start++]; | |
} | |
cout << "\n" << endl; | |
}while(1); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
vector<int>vt; | |
bool pytagoras(double x, double y, double z){ | |
if(z * z == x*x + y*y){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
int main(){ | |
const int size = 100; | |
char *input; | |
input = (char*)malloc(sizeof(char)*size); // 동적 메모리 선언은 이렇게 한다. | |
memset(input,0,sizeof(char)*size); /* | |
input의 갯수를 모를때는 Character array[크게] + memset + fget + strtok 으로 받는다. | |
*/ | |
fgets(input,size*sizeof(char),stdin); | |
char *cut = strtok(input," "); | |
do{ | |
vt.push_back(atoi(cut)); | |
} while( (cut = strtok(NULL," ")) != NULL); | |
/* strtok은 한 번 문자열을 자르고 atoi로 바꾸고, 다시 자른 cut이 NULL이 아닐때까지 한다. */ | |
sort(vt.begin(), vt.end()); | |
vector<int>str; | |
for (int i = 0; i<vt.size(); i++){ | |
for(int j = i+1; j<vt.size(); j++){ | |
for (int k = j+1; k<vt.size(); k++){ | |
if (pytagoras(vt[i], vt[j], vt[k]) == true){ | |
str.push_back(vt[i]); | |
str.push_back(vt[j]); | |
str.push_back(vt[k]); | |
} | |
} | |
} | |
} | |
int k = 0; | |
while(1){ | |
for (int j = 0; j<3; j++){ | |
cout << str[k++] << " "; | |
} | |
cout << endl; | |
if(k >= str.size()) break; | |
} | |
cout << endl; | |
free(input); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int makenum (int x, int dig){ | |
int sum = 0; | |
for (int i =0 ;i<dig; i++){ | |
sum = sum + x * pow(10,i); | |
} | |
return sum; | |
} | |
int main(){ | |
char *input; | |
const int size = 1000; | |
input = (char*)malloc(size); | |
// | |
fgets(input,size,stdin); | |
vector<int>vt; | |
// | |
char *cut = strtok(input," "); | |
do{ | |
vt.push_back(atoi(cut)); | |
}while( (cut = strtok(NULL," ")) != NULL ); | |
// | |
/*for (int i =0; i<vt.size(); i++){ | |
cout << vt[i] << " "; | |
}*/ | |
vector<int>digit; | |
int digitnum; | |
int divnum; | |
for (int i = 0; i<vt.size(); i++){ | |
divnum = vt[i]; digitnum = 0; | |
for (int j = 0; divnum>0; j++){ | |
divnum /= 10; digitnum++; | |
} | |
digit.push_back(digitnum); | |
} | |
// | |
/* cout << endl; | |
for (int i = 0; i<digit.size(); i++){ | |
cout << digit[i] << " "; | |
} | |
cout << endl;*/ | |
vector<int>onedigit; | |
for (int i = 0; i<vt.size(); i++){ | |
onedigit.push_back(vt[i]/(pow(10,digit[i]-1))); | |
} | |
// | |
/* cout << endl; | |
for (int i = 0; i<onedigit.size(); i++){ | |
cout << onedigit[i] << " "; | |
} | |
cout << endl;*/ | |
// | |
int temp = 0; | |
int temponedigit = 0 ; | |
int tempdigit = 0; | |
for (int i =0 ; i< vt.size(); i++){ | |
for (int j = i+1; j<vt.size(); j++){ | |
if (onedigit[i] < onedigit[j]){ | |
temp = vt[i]; temponedigit = onedigit[i]; tempdigit = digit[i]; | |
vt[i] = vt[j]; onedigit[i] = onedigit[j]; digit[i] = digit[j]; | |
vt[j] = temp; onedigit[j] = temponedigit; digit[j] = tempdigit; | |
} | |
else if (onedigit[i] == onedigit[j] && vt[i] > vt[j] && (vt[i] < makenum(onedigit[j] , digit[i]))){ | |
temp = vt[i]; temponedigit = onedigit[i]; tempdigit = digit[i]; | |
vt[i] = vt[j]; onedigit[i] = onedigit[j]; digit[i] = digit[j]; | |
vt[j] = temp; onedigit[j] = temponedigit; digit[j] = tempdigit; | |
} | |
} | |
} | |
for (int i = 0; i<vt.size(); i++){ | |
cout << vt[i]; | |
} | |
free(input); | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <vector> | |
#include <cstdio> | |
#include <cmath> | |
using namespace std; | |
int main(){ | |
char input [100]; | |
fgets(input,100,stdin); | |
vector<int>vt; | |
for(int i=0; i<strlen(input)-1; i++){ | |
switch (input[i]){ | |
case '0': | |
vt.push_back(0); | |
break; | |
case '1': | |
vt.push_back(1); | |
break; | |
case '2': | |
vt.push_back(2); | |
break; | |
case '3': | |
vt.push_back(3); | |
break; | |
case '4': | |
vt.push_back(4); | |
break; | |
case '5': | |
vt.push_back(5); | |
break; | |
case '6': | |
vt.push_back(6); | |
break; | |
case '7': | |
vt.push_back(7); | |
break; | |
case '8': | |
vt.push_back(8); | |
break; | |
case '9': | |
vt.push_back(9); | |
break; | |
} | |
} | |
int a,sum; | |
sum = 0; | |
for (int i=0;i<vt.size();i++){ | |
a = vt[i]*pow(10,(vt.size()-1-i)); | |
sum = a+sum; | |
} | |
int celcius = (sum - 30) / 2; | |
cout << celcius << "C"; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
float x,y,temp; | |
cin >> x; | |
cin >> y; | |
if(x>y){ | |
x = temp; | |
x = y; | |
y = temp; | |
} | |
// | |
int x1,x2; // [x1, x2] | |
if (x - (int)x == 0){ | |
x1 = (int)x; | |
} | |
else { | |
x1 = (int)x +1; | |
} | |
x2 = (int)y; | |
// | |
int n=1; | |
int k=0; | |
int arr[x2]; arr[0] = 2; | |
for (int i=2;i<=x2;i++){ | |
for (int j=2;j<i;j++){ | |
if (i%j ==0){ | |
k = 0; | |
break; | |
} | |
else { | |
k = i; | |
} | |
} | |
if (k != 0){ | |
arr[n++] = k; | |
} | |
} | |
// | |
for (int i=0;i<n;i++){ | |
if(arr[i] >= x1){ | |
cout << arr[i] << " "; | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
int main(){ | |
int myint; | |
std::vector<int> vi; | |
for(int i=0; i<3;i++){ | |
cin >> myint; | |
vi.push_back(myint); | |
} | |
sort(vi.begin(),vi.end()); | |
int x = vi[0] * vi[0]; | |
int y = vi[1] * vi[1]; | |
int z = vi[2] * vi[2]; | |
if (z == x+y){ | |
cout << "Rectangular"; | |
} | |
else if(z < x+y){ | |
cout << "Acute"; | |
} | |
else { | |
cout << "Obtuse"; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int main(){ | |
const int size = 500; | |
char *input; | |
input = (char*)malloc(sizeof(char)* size); | |
cin >> input; | |
vector<char>vt; | |
for (int i = 0; i<strlen(input); i++){ | |
if (input[i] != '0'){ | |
vt.push_back(input[i]); | |
} | |
} | |
for (int i = 0 ; i<strlen(input) - vt.size(); i++){ | |
vt.push_back('0'); | |
} | |
vt.push_back('0'); | |
for (int i = 0; i<=vt.size(); i++){ | |
cout << vt[i]; | |
} | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <ctime> | |
#include <vector> | |
#include <algorithm> | |
#include <cstring> | |
#include <cstdio> | |
#include <cstdlib> | |
using namespace std; | |
int main(){ | |
int numinput; | |
cin >> numinput; | |
int array[numinput]; | |
for (int i =0; i<numinput; i++){ | |
cin >> array[i]; | |
} | |
int count = 0; | |
int dup; int miss; | |
vector<int> vt; | |
for (int i =0; i<numinput; i++){ | |
vt.push_back(i+1); | |
} | |
// check | |
for (int i = 0 ; i<numinput; i++){ | |
for (int j = i+1; j<numinput; j++){ | |
if (array[i] == array[j]){ | |
count = 1; | |
break; | |
} | |
} | |
if (count){ | |
dup = array[i]; | |
} | |
for (int k=0; k<numinput; k++){ | |
if(array[i] != vt[k]){ | |
miss = vt[k]; | |
} | |
} | |
} | |
cout << miss << " " << dup; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ctime> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <cstdio> | |
#include <cmath> | |
#include <sstream> | |
#include <fstream> | |
using namespace std; | |
int main(){ | |
const int size = 500; | |
char *input; | |
input = (char*)malloc(sizeof(char)*size); | |
fgets(input,sizeof(char)*size,stdin); | |
vector<int>vt; | |
vector<int>vtminus; | |
vector<int>vtzero; | |
vector<int>vtplus; | |
char *cut = strtok(input," "); | |
do{ | |
vt.push_back(atoi(cut)); | |
}while( (cut = strtok(NULL," ")) != NULL); | |
for (int i = 0; i<vt.size(); i++){ | |
if (vt[i] < 0){ | |
vtminus.push_back(vt[i]); | |
} | |
else if (vt[i] == 0 ){ | |
vtzero.push_back(vt[i]); | |
} | |
else{ | |
vtplus.push_back(vt[i]); | |
} | |
} | |
int minus = 0; | |
int zero = 0; | |
int plus = 0; | |
while(1){ | |
cout << vtminus[minus++] << " "; | |
if (minus >= vtminus.size()) break; | |
} | |
while(1){ | |
cout << vtzero[zero++] << " "; | |
if (zero >= vtzero.size()) break; | |
} | |
while(1){ | |
cout << vtplus[plus++] << " "; | |
if (plus >= vtplus.size()) break; | |
} | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <cstring> | |
#include <cstdlib> | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
char excelrem (int what){ | |
switch(what){ | |
case 0: return 'Z'; break; | |
case 1: return 'A'; break; | |
case 2: return 'B'; break; | |
case 3: return 'C'; break; | |
case 4: return 'D'; break; | |
case 5: return 'E'; break; | |
case 6: return 'F'; break; | |
case 7: return 'G'; break; | |
case 8: return 'H'; break; | |
case 9: return 'I'; break; | |
case 10: return 'J'; break; | |
case 11: return 'K'; break; | |
case 12: return 'L'; break; | |
case 13: return 'M'; break; | |
case 14: return 'N'; break; | |
case 15: return 'O'; break; | |
case 16: return 'P'; break; | |
case 17: return 'Q'; break; | |
case 18: return 'R'; break; | |
case 19: return 'S'; break; | |
case 20: return 'T'; break; | |
case 21: return 'U'; break; | |
case 22: return 'V'; break; | |
case 23: return 'W'; break; | |
case 24: return 'X'; break; | |
case 25: return 'Y'; break; | |
case 26: return 'Z'; break; | |
} | |
} | |
int main(){ | |
int input; | |
vector<char>vt; | |
scanf("%d", &input); | |
int ans = input; | |
int rem = ans%26; | |
int count = 0; | |
char temp; | |
while(1){ | |
if (count == 0){ | |
vt.push_back(excelrem(rem+1)); | |
count ++ ; | |
} | |
else { | |
vt.push_back(excelrem(rem)); | |
count ++ ; | |
} | |
if ((ans < 26) && (count > 1)) break; | |
ans = ans/26; | |
rem = ans%26; | |
} | |
for (int i = 0; i<(vt.size()/2) ; i++){ | |
temp = vt[vt.size()-1-i]; | |
vt[vt.size()-1-i] = vt[i]; | |
vt[i] = temp; | |
} | |
for (int i=0; i<vt.size(); i++){ | |
printf("%c",vt[i]); | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <cstdlib> | |
using namespace std; | |
int main(){ | |
char A [100]; | |
char B [100]; | |
cin >> A; | |
cin >> B; | |
int lenA = strlen(A); | |
int lenB = strlen(B); | |
int match = 0; | |
for (int i=0;i<lenA;i++){ | |
for (int j=0;j<lenB;j++){ | |
if (A[i] == B[j]){ | |
match = 1; | |
} | |
else { | |
match = 0; | |
} | |
} | |
} | |
if (match == 1){ | |
cout << 1; | |
} | |
else { | |
cout << 0; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
int input; | |
digit = 0; | |
int sum = 0; | |
int arr[30]; | |
scanf("%d",&input); | |
for(int i=0; input >= 1; i++){ | |
arr[i] = input % 10; | |
input /= 10; | |
digit++; | |
} | |
for(int i=0; i<digit;i++){ | |
sum = sum + arr[i]; | |
} | |
printf("%d",sum); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
void read1(int x){ | |
switch (x){ | |
case 2: | |
cout << "ten "; | |
break; | |
case 3: | |
cout << "hundreds "; | |
break; | |
case 4: | |
cout << "thousands "; | |
break; | |
case 5: | |
cout << " ten thousands "; | |
break; | |
case 6: | |
cout << " hundred thousands "; | |
break; | |
case 7: | |
cout << " millions "; | |
break; | |
case 8: | |
cout << " ten millions "; | |
break; | |
case 9: | |
cout << " thousands millions "; | |
break; | |
} | |
} | |
void read2(int y){ | |
switch (y){ | |
case 1: | |
cout << "one "; | |
break; | |
case 2: | |
cout << "two "; | |
break; | |
case 3: | |
cout << "three "; | |
break; | |
case 4: | |
cout << "four "; | |
break; | |
case 5: | |
cout << "five "; | |
break; | |
case 6: | |
cout << "six "; | |
break; | |
case 7: | |
cout << "seven "; | |
break; | |
case 8: | |
cout << "eight "; | |
break; | |
case 9: | |
cout << "nine "; | |
break; | |
} | |
} | |
int main(){ | |
int input; | |
vector<int> vt; | |
cin >> input; | |
for (int i=0; input >= 1; i++){ | |
vt.push_back(input % 10); | |
input /= 10; | |
} | |
int digit = vt.size(); | |
int temp; | |
for (int i=0;i<digit/2; i++){ | |
temp = vt[digit-1-i]; | |
vt[digit-1-i] = vt[i]; | |
vt[i] = temp; | |
} | |
for (int i = 0; i<digit; i++){ | |
if (digit == 1){ | |
read2(vt[i]); | |
break; | |
} | |
else{ | |
read2(vt[i]); | |
if (vt[i] != 0){ | |
read1 (digit-i); | |
} | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <ctime> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <algorithm> | |
#include <vector> | |
#include <conio.h> | |
using namespace std; | |
int main(){ | |
char input1[100]; | |
char input2[100]; | |
char temp[100]; | |
cin >> input1; | |
cin >> input2; | |
int samecount = 0; | |
int remember = 0; | |
int iremember = 0; | |
vector<int>str; | |
if (strlen(input2)> strlen(input1)){ | |
strcpy(temp,input2); | |
strcpy(input2, input1); | |
strcpy(input1, temp); | |
} | |
for (int i =0; i<strlen(input1); i++){ | |
samecount = 0; iremember = i; | |
for (int j=0; j<strlen(input2); j++){ | |
if(input1[i] == input2[j]){ | |
i++; samecount++; | |
} | |
else{ | |
j++; | |
} | |
} | |
if (samecount > 0){ | |
str.push_back(iremember); | |
str.push_back(samecount); // odd num | |
cout << "Adreess : " << iremember << endl; | |
cout << "How many :" << samecount << endl; | |
} | |
i = iremember; | |
} | |
cout << endl; | |
int samemax = str[1]; | |
int imaxremember = str[0]; | |
if (str[1] > 0){ | |
for (int i = 1; i<str.size()-1 ; i += 2){ | |
if(str[i] > str[1]){ | |
samemax = str[i]; // i is samecount | |
imaxremember = str[i-1]; | |
} | |
} | |
} | |
if (samemax > 0){ | |
cout << "the answer : "; | |
for (int i = 0; i < samemax; i++){ | |
cout << input1[imaxremember++]; | |
} | |
cout << endl; | |
} | |
else { | |
cout <<"No same value"; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <cstdio> | |
#include <vector> | |
using namespace std; | |
int main(){ | |
char input [100]; | |
fgets(input,100,stdin); | |
/* It is equivallent to the operation "cin" | |
*/ | |
vector<int>vt; | |
for (int i = 0; i<strlen(input); i++){ | |
if (input[i] == '0'){ // When the array is characer, every components should be contained by ' '; | |
vt.push_back(0); | |
} | |
else if(input[i] == '1'){ | |
vt.push_back(1); | |
} | |
} | |
for (int i=0;i<vt.size();i++){ | |
if (vt[i] == 1){ | |
cout << i+1; | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/HansJung/6034484#file-8_-cpp-L16
http://www.cplusplus.com/doc/tutorial/variables/
char type에 대한 설명이 나와있어~ 이해 안되면 다시 물어봐~