c언어 질문이요

gmawhaan88의 이미지

안녕하세요 c언어공부 고민이 있어서 올립니다

뇌구조가 이상해서 그런지 문제를 풀때마다 어렵게 갑니다.

예를들면 문제가

숫자 세개를 입력했을때 작은수부터 차례대로 나오게 하시오.
ex) input:3 1 2
output:1 2 3

제가 푼내용

#include <stdio.h>
 
int main(void)
{
	int a=0,b=0,c=0;
 
	scanf_s("%d %d %d", &a, &b, &c);
 
 
	if(a<b)
	{
		if(b<c)
			printf("%d %d %d\n", a,b,c);
		else
		{
			if(a<c)
				printf("%d %d %d\n", a,c,b);
			else
				printf("%d %d %d\n", c,a,b);
		}
	}
	else
	{
		if(b<c)
		{
			if(a<c)
				printf("%d %d %d\n", b,a,c);
			else
				printf("%d %d %d\n", b,c,a);
		}
		else
		{
			if(a<c)
				printf("%d %d %d\n", a,c,b);
			else
				printf("%d %d %d\n", c,b,a);
		}
	}
 
 
	return 0;
 
}

어떤분은 스왑하는 방법으로 훨씬 간결하게 하던데

이게 짬밥의 차이인가요 아니면 문제를 풀때 뭔가를 설계?하고 해야 하는건가요

시간이 지나면 좋아지는건지..

문제 하나씩 풀때마다 재능이없는건가 하고 생각하게 됩니다

초보수준에서 간결하고 효율적인 코딩 팁같은거 있나요

gmawhaan88의 이미지

여기는 글 수정 못하나요?

raymundo의 이미지

부등호를 html 태그로 인식해서 그럴 겁니다.

소스 코드 앞뒤에 code 태그를 넣어주세요.

(code lang="c") -- 괄호 대신에 부등호로.
printf("...");
(/code) -- 여기도 마찬가지

좋은 하루 되세요!

김정균의 이미지

보정해 드렸습니다. code는 <code>~</code> 블럭으로 감싸 주세요.

김정균의 이미지

설계라는 것이 어떻게 만들것이냐라는 것이죠. 알고리즘을 논할 때는 얼마나 더 효율적으로 할 것이냐의 문제인 것 같고, 님의 경우에는 알고리즘을 이해하기 전에 어떤 방법으로 문제를 해결할 것이냐를 접해보는 것도 나쁘지 않을 것 같습니다.

복잡하게 생각하지 않는다면, 님이 제시한 문제는 sort를 생각하면 간단하게 해결이 되겠죠.

http://stackoverflow.com/questions/1787996/c-library-function-to-do-sort

코드 같은 것들을 살펴보시고 이해를 하시면서 해결할 방법들을 고민해 보세요. 서울로 가는 길은 엄청나게 많이 있다는 점도 중요하다고 생각합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.