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

 
(사용자 2명의 중간 판 2개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==C++==
==C++==
{{카타|8급|C++|2}}
{{카타|8급|C++|2}}
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
std::string greet(std::string name)  
std::string greet(std::string name)  
{
{
9번째 줄: 9번째 줄:
   return "Hello, " + name + "!";
   return "Hello, " + name + "!";
}
}
</source>
</syntaxhighlight>
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
std::string greet(std::string name)  
std::string greet(std::string name)  
{
{
   return "Hello, " + ( name == "Johnny" ? "my love" : name) + "!";
   return "Hello, " + ( name == "Johnny" ? "my love" : name) + "!";
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
{{카타|8급|PHP|2}}
{{카타|8급|PHP|2}}
<source lang='php'>
<syntaxhighlight lang='php'>
function greet($name) {
function greet($name) {
   if ($name == 'Johnny') {
   if ($name == 'Johnny') {
26번째 줄: 26번째 줄:
   return "Hello, $name!";
   return "Hello, $name!";
}
}
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
function greet($name) {
function greet($name) {
   $name = $name === 'Johnny' ? 'my love' : $name;
   $name = $name === 'Johnny' ? 'my love' : $name;
   return 'Hello, ' . $name . '!';
   return 'Hello, ' . $name . '!';
}
}
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
function greet($name) {
function greet($name) {
   return $name === 'Johnny' ? 'Hello, my love!' : "Hello, $name!";
   return $name === 'Johnny' ? 'Hello, my love!' : "Hello, $name!";
}
}
</source>
</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 }}