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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
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>

2020년 11월 2일 (월) 02:48 판

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!";
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}