"카타 8급 Counting sheep..."의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
1번째 줄: 1번째 줄:
==C++==
==C++==
{{카타|8급|C++|2}}
{{카타|8급|C++|2}}
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
#include <algorithm>
#include <algorithm>
using namespace std;  
using namespace std;  
7번째 줄: 7번째 줄:
   return count(arr.cbegin(), arr.cend(), true);
   return count(arr.cbegin(), arr.cend(), true);
}
}
</source>
</syntaxhighlight>
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
#include <algorithm>
#include <algorithm>
using namespace std;  
using namespace std;  
14번째 줄: 14번째 줄:
   return count(arr.begin(), arr.end(), true);
   return count(arr.begin(), arr.end(), true);
}
}
</source>
</syntaxhighlight>
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
using namespace std;  
using namespace std;  
int count_sheep(vector<bool> arr) {
int count_sheep(vector<bool> arr) {
24번째 줄: 24번째 줄:
   return res;
   return res;
}
}
</source>
</syntaxhighlight>


==Java==
==Java==
[[분류: 카타 8급 Java]]
[[분류: 카타 8급 Java]]
<source lang='java'>
<syntaxhighlight lang='java'>
public class Counter {
public class Counter {
   public int countSheeps(Boolean[] arrayOfSheeps) {
   public int countSheeps(Boolean[] arrayOfSheeps) {
36번째 줄: 36번째 줄:
   }
   }
}
}
</source>
</syntaxhighlight>


==Python==
==Python==
[[분류: 카타 8급 Python]]
[[분류: 카타 8급 Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
def count_sheeps(arrayOfSheeps):
def count_sheeps(arrayOfSheeps):
   return arrayOfSheeps.count(True)
   return arrayOfSheeps.count(True)
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python'>
def count_sheeps(arrayOfSheeps):
def count_sheeps(arrayOfSheeps):
   return len([x for x in arrayOfSheeps if x])
   return len([x for x in arrayOfSheeps if x])
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python'>
def count_sheeps(arrayOfSheeps):
def count_sheeps(arrayOfSheeps):
   count = 0
   count = 0
55번째 줄: 55번째 줄:
       count += 1
       count += 1
   return count
   return count
</source>
</syntaxhighlight>

2020년 11월 2일 (월) 02:48 기준 최신판

1 C++[ | ]

#include <algorithm>
using namespace std; 
int count_sheep(vector<bool> arr) {
  return count(arr.cbegin(), arr.cend(), true);
}
#include <algorithm>
using namespace std; 
int count_sheep(vector<bool> arr) {
  return count(arr.begin(), arr.end(), true);
}
using namespace std; 
int count_sheep(vector<bool> arr) {
  int res = 0;
  for(bool x: arr) {
    if( x ) res++;
  }
  return res;
}

2 Java[ | ]

public class Counter {
  public int countSheeps(Boolean[] arrayOfSheeps) {
    int count = 0;
    for (Boolean b : arrayOfSheeps) if (b) count++;
    return count;
  }
}

3 Python[ | ]

def count_sheeps(arrayOfSheeps):
  return arrayOfSheeps.count(True)
def count_sheeps(arrayOfSheeps):
  return len([x for x in arrayOfSheeps if x])
def count_sheeps(arrayOfSheeps):
  count = 0
  for sheep in arrayOfSheeps:
    if sheep:
      count += 1
  return count
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}