Created
February 26, 2016 17:53
-
-
Save HyeonWooKim/ecfe308a702c4a0fa333 to your computer and use it in GitHub Desktop.
실전 C프로그래밍 문제모음
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
/************************************** | |
국민대학교 컴퓨터공학부 20103324 김현우 | |
문제 8 : 시간 계산 | |
***************************************/ | |
#include <iostream> | |
#include <fstream> | |
#include <cstdlib> | |
using namespace std; | |
void main(void) | |
{ | |
ifstream inStream; | |
int numTestCases; | |
inStream.open("input.txt"); | |
if(inStream.fail()) | |
{ | |
cerr << "Input file opening failed\n"; | |
exit(1); | |
} | |
inStream >> numTestCases; | |
for(int i=0; i<numTestCases; i++) | |
{ | |
int people,H,M,S,h,m,s,w,o,r,k,result; | |
result=w=o=r=k=0; | |
inStream >> people; | |
for(int j=0; j<people; j++) | |
{ | |
inStream >> H >> M >> S >> h >> m >> s; | |
result+=(h*3600+m*60+s)-(H*3600+M*60+S); | |
} | |
w=result/86400; | |
result%=86400; | |
o=result/3600; | |
result%=3600; | |
r=result/60; | |
result%=60; | |
k=result; | |
cout << w << " " << o << " " << r << " " << k << "\n"; | |
} | |
inStream.close(); | |
} |
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
/************************************** | |
국민대학교 컴퓨터공학부 20103324 김현우 | |
문제 9 : 주어진 정수의 최대, 최소 구하기 | |
***************************************/ | |
#include <iostream> | |
#include <fstream> | |
#include <cstdlib> | |
using namespace std; | |
int getNum(int num1, int num2, bool isgetmax); | |
void main(void) | |
{ | |
ifstream inStream; | |
int numTestCases; | |
inStream.open("input.txt"); | |
if(inStream.fail()) | |
{ | |
cerr << "Input file opening failed\n"; | |
exit(1); | |
} | |
inStream >> numTestCases; | |
for(int i=0; i<numTestCases; i++) | |
{ | |
int count,val,min,max; | |
inStream >> count >> val; | |
min=max=val; | |
for(int j=1; j<count; j++) | |
{ | |
inStream >> val; | |
max = getNum(val, max, true); | |
min = getNum(val, min, false); | |
} | |
cout << max << " " << min << "\n"; | |
} | |
inStream.close(); | |
} | |
int getNum(int num1, int num2, bool ismax) | |
{ | |
if(ismax) return num1>=num2?num1:num2; | |
else return num1<=num2?num1:num2; | |
} |
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
/************************************** | |
국민대학교 컴퓨터공학부 20103324 김현우 | |
문제 10 : 숫자로 삼각형 출력하기 | |
***************************************/ | |
#include <iostream> | |
#include <fstream> | |
#include <cstdlib> | |
using namespace std; | |
void drawTriangle(int size); | |
void main(void) | |
{ | |
ifstream inStream; | |
int numTestCases; | |
inStream.open("input.txt"); | |
if(inStream.fail()) | |
{ | |
cerr << "Input file opening failed\n"; | |
exit(1); | |
} | |
inStream >> numTestCases; | |
for(int i=0; i<numTestCases; i++) | |
{ | |
int sizeOfTriangle; | |
inStream >> sizeOfTriangle; | |
drawTriangle(sizeOfTriangle); | |
} | |
inStream.close(); | |
} | |
void drawTriangle(int size) | |
{ | |
for(int i=1; i<=size; i++) | |
{ | |
int temp1=size, temp2=i; | |
cout << temp2 << " "; | |
for(int j=1; j<i; j++) | |
{ | |
temp2+=--temp1; | |
cout << temp2 << " "; | |
} | |
cout << "\n"; | |
} | |
} |
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
/************************************** | |
국민대학교 컴퓨터공학부 20103324 김현우 | |
문제 12 : 다이아몬드 모양 출력하기 | |
***************************************/ | |
#include <iostream> | |
#include <fstream> | |
#include <cstdlib> | |
using namespace std; | |
void drawDiamond(int size); | |
void main(void) | |
{ | |
ifstream inStream; | |
int numTestCases; | |
inStream.open("input.txt"); | |
if(inStream.fail()) | |
{ | |
cerr << "Input file opening failed\n"; | |
exit(1); | |
} | |
inStream >> numTestCases; | |
for(int i=0; i<numTestCases; i++) | |
{ | |
int sizeOfTriangle; | |
inStream >> sizeOfTriangle; | |
drawDiamond(sizeOfTriangle); | |
} | |
inStream.close(); | |
} | |
void drawDiamond(int size) | |
{ | |
int temp1=size/2+1, temp2=1, k=1; | |
for(int i=1; i<=size; i++) | |
{ | |
k=1; | |
while(k++<temp1) cout << "*"; | |
k=1; | |
while(k++<=temp2) cout << "+"; | |
k=1; | |
while(k++<temp1) cout << "*"; | |
temp1=i<(size/2+1) ? temp1-1 : temp1+1; | |
temp2=i<(size/2+1) ? temp2+2 : temp2-2; | |
cout << "\n"; | |
} | |
} |
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
/************************************** | |
국민대학교 컴퓨터공학부 20103324 김현우 | |
문제 12 : 모래시계 출력하기 | |
***************************************/ | |
#include <iostream> | |
#include <fstream> | |
#include <cstdlib> | |
using namespace std; | |
void drawHourGlass(int size); | |
void main(void) | |
{ | |
ifstream inStream; | |
int numTestCases; | |
inStream.open("input.txt"); | |
if(inStream.fail()) | |
{ | |
cerr << "Input file opening failed\n"; | |
exit(1); | |
} | |
inStream >> numTestCases; | |
for(int i=0; i<numTestCases; i++) | |
{ | |
int sizeOfTriangle; | |
inStream >> sizeOfTriangle; | |
drawHourGlass(sizeOfTriangle); | |
} | |
inStream.close(); | |
} | |
void drawHourGlass(int size) | |
{ | |
int temp1=0, temp2=size; | |
for(int i=1; i<=size; i++) | |
{ | |
int k=0; | |
while(k++<temp1) cout << "-"; | |
k=0; | |
while(k<temp2) | |
{ | |
if(k++%2==1) cout << "+"; else cout << "*"; | |
} | |
k=0; | |
while(k++<temp1) cout << "-"; | |
temp1=i<(size/2+1) ? temp1+1 : temp1-1; | |
temp2=i<(size/2+1) ? temp2-2 : temp2+2; | |
cout << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment