๐Ÿ’ป Dev & CSC++ Programming

C++ Programming Ch.2 Exercise 8 Solution

Problem: ํ•œ ๋ผ์ธ์— ';' ์œผ๋กœ 5๊ฐœ์˜ ์ด๋ฆ„์„ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ž…๋ ฅ๋ฐ›์•„, ๊ฐ ์ด๋ฆ„์„ ๋Š์–ด๋‚ด์–ด ํ™”๋ฉด์— ์ถœ๋ ฅํ•˜๊ณ  ๊ฐ€์žฅ ๊ธด ์ด๋ฆ„์„ ํŒ๋ณ„ํ•˜๋ผ. Objective & Hints: cin.getline()์œผ๋กœ ๋ฌธ์ž์—ด ์ฝ๊ธฐ ';'๊นŒ์ง€ ๋ฌธ์ž์—ด์„ ์ฝ๊ณ ์ž ํ•˜๋ฉด ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  1 2 char name[100]; cin.getline(name, 100, ';'); 5๊ฐœ ์ฝ์–ด์•ผ ํ•˜๋‹ˆ 5๋ฒˆ ๋ฃจํ”„๋ฅผ ๋ˆ๋‹ค. Execution Result: Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include #include using namespace std; int main() { int A=0; int i; char name[100]; char longName[100]; cout << "5 ๋ช…์˜ ์ด๋ฆ„์„ ';' ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ž…๋ ฅํ•˜์„ธ์š” \n>>"; for(i=1;i<6;i++){ cin.getline(name,100,';'); cout << i << " : " << name << endl; if(A < strlen(name)) { A = strlen(name); strcpy(longName,name); } } cout << "๊ฐ€์žฅ ๊ธด ์ด๋ฆ„์€ " << longName; return 0; } Explanation: ...

February 28, 2020 ยท 1 min ยท Sobamemil