"카타 8급 Jenny's secret message"의 두 판 사이의 차이

(새 문서: ==C++== {{카타|8급|C++|2}} <source lang='cpp'> </source>)
 
 
(사용자 2명의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==C++==
==C++==
{{카타|8급|C++|2}}
{{카타|8급|C++|2}}
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
</source>
std::string greet(std::string name)
{
  if(name == "Johnny") {
    return "Hello, my love!";
  }
  return "Hello, " + name + "!";
}
</syntaxhighlight>
<syntaxhighlight lang='cpp'>
std::string greet(std::string name)
{
  return "Hello, " + ( name == "Johnny" ? "my love" : name) + "!";
}
</syntaxhighlight>
 
==PHP==
{{카타|8급|PHP|2}}
<syntaxhighlight lang='php'>
function greet($name) {
  if ($name == 'Johnny') {
    return 'Hello, my love!';
  }
  return "Hello, $name!";
}
</syntaxhighlight>
<syntaxhighlight lang='php'>
function greet($name) {
  $name = $name === 'Johnny' ? 'my love' : $name;
  return 'Hello, ' . $name . '!';
}
</syntaxhighlight>
<syntaxhighlight lang='php'>
function greet($name) {
  return $name === 'Johnny' ? 'Hello, my love!' : "Hello, $name!";
}
</syntaxhighlight>
 
==Rust==
[[분류: 카타 8급 Rust]]
<syntaxhighlight lang='rust'>
fn greet(input : &str) -> String {
  match input {
    "Johnny" => "Hello, my love!".to_string(),
    _        => format!("Hello, {}!", input),
  }
}
</syntaxhighlight>
<syntaxhighlight lang='rust'>
fn greet(input : &str) -> String {
  if input == "Johnny" {
    return "Hello, my love!".to_string();
  };
  return format!("Hello, {}!", input);
}
</syntaxhighlight>

2023년 8월 16일 (수) 19:32 기준 최신판

1 C++[ | ]

std::string greet(std::string name) 
{
  if(name == "Johnny") {
    return "Hello, my love!";
  }
  return "Hello, " + name + "!";
}
std::string greet(std::string name) 
{
  return "Hello, " + ( name == "Johnny" ? "my love" : name) + "!";
}

2 PHP[ | ]

function greet($name) {
  if ($name == 'Johnny') {
    return 'Hello, my love!';
  }
  return "Hello, $name!";
}
function greet($name) {
  $name = $name === 'Johnny' ? 'my love' : $name;
  return 'Hello, ' . $name . '!';
}
function greet($name) {
  return $name === 'Johnny' ? 'Hello, my love!' : "Hello, $name!";
}

3 Rust[ | ]

fn greet(input : &str) -> String {
  match input {
    "Johnny" => "Hello, my love!".to_string(),
    _        => format!("Hello, {}!", input),
  }
}
fn greet(input : &str) -> String {
  if input == "Johnny" {
    return "Hello, my love!".to_string();
  };
  return format!("Hello, {}!", input);
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}