MedusaCppStudy í�¬ê²½ ìˆ™ì œ ¶
ì •ì‚¬ê°�형ì�„ 짜봤습니다
~cpp
#include<iostream>
using namespace std;
int main()
{
int x;
cin >> x;
for(int i = 0; i < x; i++)
{
cout << "* ";
}
cout << endl;
for(int j = 0; j < (x-2); j++)
{
cout << "*";
for(int k = 0; k < (x-2); k++)
{
cout << " ";
}
cout << " *" << endl;
}
for(int l = 0; l < x; l++)
{
cout << "* ";
}
cout << endl;
return 0;
}
삼�형� 짜봤군요
~cpp
#include<iostream>
using namespace std;
int main()
{
int x;
cin >> x;
for(int i = 0; i < x-1; i++)
{
if(i == 0)
{
for(int j = (x-i-1); j > 0; j--)
{
cout << " ";
}
cout << "*" << endl;
}
else
{
for(int j = (x-i-1); j > 0; j--)
{
cout << " ";
}
cout << "*";
for(int k = 0; k < (2*i-1); k++)
{
cout << " ";
}
cout << "*" << endl;
}
}
for(int l = 0; l < x; l++)
{
cout << "* ";
}
cout << endl;
return 0;
}
문장 ìž…ë ¥ì‹œ 가장 긴, ì§§ì�€ 단어ì�˜ 길ì�´ 구하기
(ì˜�ì–´ìž…ë ¥!! 한글ì�€ 곱하기 2해서 나옴)
ì�´ëŸ° ë¬¸ì œë¥¼ 보니 ;를 만났ì�„때 문장 ë��ì�´ë�¼ê³ 했는ë�°
ì „ 그냥 엔터치면 문장 ë��ì�´êµ°ìš”. ë� ìƒ�ê´€ì—†ê² ì£ ?
(ì˜�ì–´ìž…ë ¥!! 한글ì�€ 곱하기 2해서 나옴)
ì�´ëŸ° ë¬¸ì œë¥¼ 보니 ;를 만났ì�„때 문장 ë��ì�´ë�¼ê³ 했는ë�°
ì „ 그냥 엔터치면 문장 ë��ì�´êµ°ìš”. ë� ìƒ�ê´€ì—†ê² ì£ ?
~cpp
#include<iostream>
#include<string.h>
using namespace std;
int num();
char str[50];
int main()
{
cout << "뛰어쓰기나 마침표 �함해서 50�내로 문장� 작성하시오" << endl;
cin.getline(str,50);
int count = 0;
int x = num();
cout << "단어 개수: " << x << endl;
int *lenth = new int [x];
int word = 0;
for(int i = 0; i < strlen(str)+1; i++)
{
if((str[i] == ' ') || (i == strlen(str)))
{
lenth[word] = count;
word++;
count = 0;
}
else if(str[i] != '.')
count++;
}
int temp;
int k = 1;
for(int l = 0; l < x-1; l++)
{
for(int m = k; m < x; m++)
{
if(lenth[l] < lenth[m])
{
temp = lenth[l];
lenth[l] = lenth[m];
lenth[m] = temp;
}
}
k++;
}
cout << "가장 긴 단어 길�: " << lenth[0] << endl;
cout << "가장 짧� 단어 길�: " << lenth[x-1] << endl;
delete lenth;
return 0;
}
int num()
{
int count2 = 1;
for(int i = 0; i < strlen(str); i++)
{
if(str[i] == ' ')
{
count2++;
}
}
return count2;
}
� 숫� 4개 골�내기.....
숫ìž�ì�˜ 개수를 ìž…ë ¥í•´ì•¼ë�˜ê²Œë°–ì—� 못 ì§œê² êµ°ìš”..
숫ìž�ì�˜ 개수를 ìž…ë ¥í•´ì•¼ë�˜ê²Œë°–ì—� 못 ì§œê² êµ°ìš”..
~cpp
#include<iostream>
using namespace std;
int main()
{
int num;
cout << "숫ìž� 개수를 ìž…ë ¥í•´ 주세요 :";
cin >> num;
cout << "숫ìž�를 차례대로 ìž…ë ¥í•´ì£¼ì„¸ìš”(숫ìž�는 서로 ë�„어쓰기로 구분한다) :" << endl;
int *pocket = new int[num];
for(int i = 0; i < num; i++)
{
cin >> pocket[i];
cin.get();
}
int temp;
int l = 1;
for(int j = 0; j < num-1; j++)
{
for(int k = l; k < num; k++)
{
if(pocket[j] < pocket[k])
{
temp = pocket[j];
pocket[j] = pocket[k];
pocket[k] = temp;
}
}
l++;
}
cout << "� 숫� 4개 :";
if(num > 4)
{
for(int m = 0; m < 4; m++)
{
cout << pocket[m] << " ";
}
}
else
{
for(int n = 0; n < num; n++)
{
cout << pocket[n] << " ";
}
}
cout << endl;
return 0;
}
ë¦¬íŒ©í† ë§� ìš”ë§�~









