submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s764617533
p00029
Accepted
from collections import Counter seq = list(input().split()) mode_word = '' cnt = 0 for k, v in Counter(seq).items(): if cnt < v: mode_word = k cnt = v max_count_word = '' for s in seq: if len(max_count_word) < len(s): max_count_word = s print(mode_word, max_count_word)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s783412288
p00029
Accepted
# coding: utf-8 from collections import Counter s = input().strip().split(" ") most_freq = Counter(s).most_common()[0][0] max_len = sorted([(len(x), x)for x in s], reverse=True)[0][1] print("{} {}".format(most_freq, max_len))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s733454463
p00029
Accepted
import collections s=list(map(str,input().split())) nc=collections.Counter(s) ans_most=nc.most_common(1)[0][0] ans_long="" for i in s: if len(ans_long)<len(i):ans_long=i print(ans_most,ans_long)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s180151717
p00029
Accepted
if __name__ == '__main__': maxL = 0 maxF = 0 strlst = list(map(str, input().split())) for s in strlst: if strlst.count(s) > maxF: maxF = strlst.count(s) maxFans = s if len(s) > maxL: maxL = len(s) maxLans = s print(maxFans, maxLans)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s585339453
p00029
Accepted
text = input().split() dic = dict(zip(text,[0 for i in range(len(text))])) for i in text: dic[i] = dic[i] + 1 max_ = max(dic.values()) for key,value in dic.items(): if value == max_: most = key max_ = 0 for i in dic.keys(): if len(i) > max_: max_ = len(i) amax_ = i print(most, amax_)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s715732726
p00029
Accepted
from statistics import * words = [w.lower() for w in input().split()] words.sort(key=len, reverse=True) print(mode(words), words[0])
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s425160635
p00029
Accepted
import collections slist = list(map(str, input().split())) sc = collections.Counter(slist) common = sc.most_common()[0][0] max = "" for s in slist: if len(max) < len(s): max = s print(common, max)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s842188766
p00029
Accepted
s = list(input().split()) print(max(s,key=s.count), max(s,key=len))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s517368229
p00029
Accepted
list = input().split() print(max(list, key=list.count), max(list, key=len))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s127301502
p00029
Accepted
s = list(input().split()) print(max(s, key=s.count), max(s, key=len))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s244471413
p00029
Accepted
from collections import Counter def process(line): longest = sorted(line, key=len) c = Counter(line) count = c.most_common(1) return count[0][0], longest[-1] line = input().split() a, b = process(line) print('{} {}'.format(a, b))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s375823565
p00029
Accepted
x = input().lower() term_data = {} for word in x.split(): if term_data.get(word) is None: term_data[word] = [0, len(word)] term_data[word][0] += 1 term_data = [(term, data) for term, data in term_data.items() ] print(max(term_data, key=lambda x:x[1][0])[0], max(term_data, key=lambda x:x[1][1])[0] )
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s234273034
p00029
Accepted
from collections import Counter sentence = input().split() cnt = Counter(sentence) print(cnt.most_common(1)[0][0], max(sentence, key=lambda x: len(x)))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s463232906
p00029
Accepted
from collections import Counter s = list(input().split()) c = Counter(s) n,m = 0,0 for e in s: if n < len(e): n = len(e) m = e print(c.most_common()[0][0],m)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s003105620
p00029
Accepted
def solve(): text = input() longest, length = '', 0 dic = {} for word in text.split(): if word in dic.keys(): dic[word] += 1 else: dic[word] = 1 if length < len(word): longest = word length = len(word) target, cnt = '', 0 for k, v in dic.items(): if v > cnt: target = k cnt = v print(target, longest) if __name__ == "__main__": solve()
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s138453021
p00029
Runtime Error
# coding: utf-8 # Your code here! a = raw_input().lower() s = a.split() ss = "" tmp = "" n = 0 for i in s: if len(ss) < len(i): ss = i for i in s: i+=" " if a.count(i) > n: n = a.count(i) tmp = i.trip() print tmp, ss
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s886572503
p00029
Runtime Error
while True: words = raw_input().strip().split(" ") count = {}; for word in words: s = count.setdefault(word, 0); count[word] = s + 1 print max(count.items(), key=lambda x: x[1])[0], max(words, key=lambda x: len(x))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s779294404
p00029
Runtime Error
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys dic = {} for s in sys.stdin: d = [ e.lower() for e in map(str,s.split()) ] for e in d: if e in dic: dic[e] += 1 else: dic[e] = 1 sdict = sorted(dic.items(),key=lambda x:-x[1]) maxnum = sdict[0][1] for i in range(len(sdict)): if sdict[i][1] == maxnum: print sdict[i][0], else: break maxlen = max([len(e) for e in d]) longterm = [ e for e in d if len(e) == maxlen ] for e in longterm: print e,
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s707426300
p00029
Runtime Error
import sys f = sys.stdin rhombus = oblong = 0 for line in f: a, b, c = map(int, line.split(',')) if a == b: rhombus += 1 if a * a + b * b == c * c: oblong += 1 print(oblong) print(rhombus)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s085030920
p00029
Runtime Error
# -*- coding: utf-8 -*- while True: try: ls = [] dic = {}# {'your' : [appeared,len]} ls = raw_input().split() for k in range(len(ls)): if ls[k] not in dic.keys(): dic[ls[k]] = [] dic[ls[k]].append(1) dic[ls[k]].append(len(ls[k])) else: dic[ls[k]][0] += 1 a=max(dic) # value[0] b=max(dic.items(), key=lambda x: x[1][1])[0] print "%s %s" % (a,b) except EOFError: break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s693346938
p00029
Runtime Error
while True: try: ls = [] dic = {}# {'your' : [appeared,len]} ls = raw_input().split() for k in range(len(ls)): if ls[k] not in dic.keys(): dic[ls[k]] = [] dic[ls[k]].append(1) dic[ls[k]].append(len(ls[k])) else: dic[ls[k]][0] += 1 a=max(dic) # value[0] b=max(dic.items(), key=lambda x: x[1][1])[0] print "%s %s" % (a,b) except EOFError: break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s336145294
p00029
Runtime Error
from math import * PI = 3.1415926535898 while True: try: arr = map(str, raw_input().strip().split()) ans1 = arr[0] ans2 = arr[0] for s in arr: if arr.count(s) > arr.count(ans1): ans1 = s if len(s) > len(ans2): ans2 = s print "%s %s" % (ans1, ans2) except EOFError: break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s221340421
p00029
Runtime Error
#encoding=utf-8 import statistics as st word1 = [] word = raw_input().split() print st.mode(word) for i in xrange(len(word)): word1.append(len(word[i])) for i in xrange(len(word)): if len(word[i]) == max(word1): print word[i]
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s178485971
p00029
Runtime Error
import statistics as st word1 = [] word = raw_input().split() for i in xrange(len(word)): word1.append(len(word[i])) for i in xrange(len(word)): if len(word[i]) == max(word1): print st.mode(word), word[i] break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s253994800
p00029
Runtime Error
import statistics as st word1 = [] word = raw_input().split() for i in xrange(len(word)): word1.append(len(word[i])) for i in xrange(len(word)): if len(word[i]) == max(word1): print(st.mode(word), word[i]) break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s015064809
p00029
Runtime Error
import sys def main(): input_line = [] test_line = 'Thank you for your mail and your lectures' # for line in test_line.split(): # input_line.append(line) for line in sys.stdin: input_line.append(line.split()) #print(input_line.count('your')) number_len = {} number_fre = {} for i in input_line: number_len.update({i:len(i)}) number_fre.update({i:test_line.count(i)}) if __name__ == '__main__': main()
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s919582965
p00029
Runtime Error
import sys def main(): input_line = [] # with open('test_data') as f: # for line in f.readline().split(): # input_line.append(line) for line in sys.stdin.readline().split(): input_line.append(line) #print(input_line) number_len = {} number_fre = {} for i in input_line: number_len.update({i:len(i)}) number_fre.update({i:input_line.count(i)}) sorted_x = sorted(number_len.items(), key=operator.itemgetter(1)) sorted_y = sorted(number_fre.items(), key=operator.itemgetter(1)) print(sorted_x[-1][0],sorted_y[-1][0]) if __name__ == '__main__': main()
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s325803005
p00029
Runtime Error
from collections import Counter def most_arise(s): c = Counter(s.split()) maxone = sorted(s.split(),key=lambda x:len(x))[-1] print("{0} {1}".format(c.most_common()[0][0],maxone)) s = raw_input() most_arise(s)
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s540057432
p00029
Runtime Error
from collections import Counter s = raw_input() c = Counter(s.split()) maxone = sorted(s.split(),key=lambda x:len(x))[-1] print("{0} {1}".format(c.most_common()[0][0],maxone))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s548446557
p00029
Runtime Error
s = raw_input() c = Counter(s.split()) maxone = sorted(s.split(),key=lambda x:len(x))[-1] print("{0} {1}".format(c.most_common()[0][0],maxone))
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s186137145
p00029
Runtime Error
for word in s: try: dic[word]+=1 except: dic[word]=1 m=0 l=0 for word, e in dic.items(): if e>m: m=e w1=word if len(word)>l: l=len(word) w2=word print w1, w2
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s637949460
p00029
Runtime Error
import datetime, sys wday_lst = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] for s in sys.stdin: m,d = map(int, s.split()) if m == 0 or d == 0: break str = '2004-%d-%d 00:00:00'%(m,d) day = datetime.datetime.strptime(str, '%Y-%m-%d %H:%M:%S') print wday_lst[day.weekday()]
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s236311609
p00029
WA: Presentation Error
from math import * PI = 3.1415926535898 while True: try: arr = map(str, raw_input().strip().split()) ans1 = "" ans2 = "" for s in arr: if arr.count(s) > arr.count(ans1): ans1 = s if len(s) > len(ans2): ans2 = s print ans1+" "+ans2 except EOFError: break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s927654948
p00029
WA: Presentation Error
from math import * PI = 3.1415926535898 while True: try: arr = map(str, raw_input().strip().split()) ans1 = "" ans2 = "" for s in arr: if arr.count(s) > arr.count(ans1): ans1 = s if len(s) > len(ans2): ans2 = s print "%s %s" % (ans1, ans2) except EOFError: break
Thank you for your mail and your lectures
your lectures
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
s858051673
p00030
Wrong Answer
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break self.ans = 0 # self.dfs(0, 0, [], n, s) for i in range(s): for j in range(s): for k in range(s): if i == j or j == k or k == i: continue else: if i + j + k == s: # print i, j, k self.ans += 1 print self.ans / 3 return None def dfs(self, num, sumNum, rec, n, s): print num, sumNum, rec, n, s if num == n: if sumNum == s: self.ans += 1 else: for i in range(s): if not i in rec and sumNum + i <= s: self.dfs(num + 1, sumNum + i, rec + [i], n, s) if __name__ == '__main__': h = Hoge() h.func()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s872165104
p00030
Wrong Answer
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break self.ans = 0 # self.dfs(0, 0, [], n, s) for i in range(s+1): for j in range(s+1): for k in range(s+1): if i >= j or j >= k or i >= k: continue else: if i + j + k == s: print i, j, k self.ans += 1 print self.ans return None def dfs(self, num, sumNum, rec, n, s): print num, sumNum, rec, n, s if num == n: if sumNum == s: self.ans += 1 else: for i in range(s): if not i in rec and sumNum + i <= s: self.dfs(num + 1, sumNum + i, rec + [i], n, s) if __name__ == '__main__': h = Hoge() h.func()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s828462610
p00030
Wrong Answer
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break self.ans = 0 # self.dfs(0, 0, [], n, s) for i in range(s+1): for j in range(s+1): for k in range(s+1): if i >= j or j >= k or i >= k: continue else: if i + j + k == s: # print i, j, k self.ans += 1 print self.ans return None def dfs(self, num, sumNum, rec, n, s): print num, sumNum, rec, n, s if num == n: if sumNum == s: self.ans += 1 else: for i in range(s): if not i in rec and sumNum + i <= s: self.dfs(num + 1, sumNum + i, rec + [i], n, s) if __name__ == '__main__': h = Hoge() h.func()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s846599749
p00030
Wrong Answer
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break self.ans = 0 # self.dfs(0, 0, [], n, s) for i in range(s): for j in range(s): for k in range(s): if i >= j or j >= k or i >= k: continue if i + j + k == s: # print i, j, k self.ans += 1 print self.ans return None # def dfs(self, num, sumNum, rec, n, s): # print num, sumNum, rec, n, s # if num == n: # if sumNum == s: # self.ans += 1 # else: # for i in range(s): # if not i in rec and sumNum + i <= s: # self.dfs(num + 1, sumNum + i, rec + [i], n, s) if __name__ == '__main__': h = Hoge() h.func()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s197203618
p00030
Wrong Answer
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break self.ans = 0 # self.dfs(0, 0, [], n, s) for i in range(10): for j in range(10): for k in range(10): if i >= j or j >= k or i >= k: continue if i + j + k == s: # print i, j, k self.ans += 1 print self.ans return None # def dfs(self, num, sumNum, rec, n, s): # print num, sumNum, rec, n, s # if num == n: # if sumNum == s: # self.ans += 1 # else: # for i in range(s): # if not i in rec and sumNum + i <= s: # self.dfs(num + 1, sumNum + i, rec + [i], n, s) if __name__ == '__main__': h = Hoge() h.func()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s897347102
p00030
Wrong Answer
# coding: utf-8 def main(): while True: a, b = map(int, input().split()) if a == 0 and b == 0: break c = 0 for i in range(b // 2): for j in range(i + 1, b): for k in range(j + 1, b): if i + j + k == b: c += 1 print(c) if __name__ == "__main__": main()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s607694993
p00030
Wrong Answer
while True: try: n,s = map(int,raw_input().split()) except EOFError: break if (n,s) == (0,0): break if s == 0 or s == 1 or s == 2: print 0 else: ls = [] for k in range(s): for l in range(1,s): if k + l > s: break for m in range(2,s): tmp = k + l + m if tmp == s and k!=l and l!=m and m!=k: tmp2 = tuple(sorted((k,l,m))) ls.append(tmp2) break print len(set(ls))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s475887093
p00030
Wrong Answer
def sum_count(n,s,r): if n==0 and s==0: return 1 if n<=0 or s<0: return 0 else: return sum([sum_count(n-1,s-i,i+1) for i in range(r,9)]) while True: n,s=map(int,raw_input().split(" ")) if n==0 and s==0: break print sum_count(n,s,0)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s333556597
p00030
Wrong Answer
def decSum(n, sm, mn): print(n,sm,mn) if mn + n > 10 : return 0 elif sum(range(mn, mn + n)) > sm or sum(range(10 - n, 10)) < sm: return 0 elif n == 1: return 1 else: a = 0 for i in range(mn, 10 if sm >= 10 else sm): a += decSum(n - 1, sm - i, i + 1) return a while True: n, sm = map(int, input().split()) if n == 0: break print(decSum(n, sm, 0))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s950933943
p00030
Wrong Answer
#encoding=utf-8 while True: x, num = map(int,raw_input().split()) if x == num == 0: break count = 0 for a in xrange(10): if num == a and x == 1: count += 1 if x > 1: for b in xrange(a + 1,10): if num == a+b and x == 2: count += 1 if x > 2: for c in xrange(b + 1,10): if num == a+b+c and x == 3: count += 1 if x > 3: for d in xrange(c + 1,10): if num == a+b+c+d and x == 4: count += 1 if x > 4: for e in xrange(d,10): if num == a+b+c+d+e and x == 5: count += 1 if x > 5: for f in xrange(10): if num == a+b+c+d+e+f and x == 6: count += 1 if x > 6: for g in xrange(10): if num == a+b+c+d+e+f+g and x == 7: count += 1 if x > 7: for h in xrange(10): if num == a+b+c+d+e+f+g+h and x == 8: count += 1 if x > 8: for i in xrange(10): if num == a+b+c+d+e+f+g+h+i and x == 9: count += 1 print count
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s110123267
p00030
Wrong Answer
import sys sys.setrecursionlimit(10000) def solve(i,wa,use): global ct,s,n if use>n: return if i==11: return if wa==s and use==n: ct+=1 return if wa>=s: return if wa<s: solve(i+1,wa,use) solve(i+1,wa+i,use+1) while 1: n,s=map(int,raw_input().split()) if n==0 and s==0: break ct=0 wa=0 solve(0,0,0) print ct
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s699613435
p00030
Wrong Answer
import sys sys.setrecursionlimit(10000) def solve(i,wa,use): global ct,s,n if use>n: return if i==11: return if wa==s and use==n: ct+=1 return if wa>s: return if wa<s: solve(i+1,wa,use) solve(i+1,wa+i,use+1) while 1: n,s=map(int,raw_input().split()) if n==0 and s==0: break ct=0 wa=0 solve(0,0,0) print ct
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s575941715
p00030
Wrong Answer
import sys sys.setrecursionlimit(10000) def solve(i,wa,use): global ct,s,n if use>n: return if i==11: return if wa==s and use==n: ct+=1 return if wa>=s: return if wa<s: solve(i+1,wa,use) solve(i+1,wa+i,use+1) while 1: n,s=map(int,raw_input().split()) if n==0 and s==0: break ct=0 wa=0 solve(0,0,0) print ct
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s479638101
p00030
Wrong Answer
import sys sys.setrecursionlimit(10000) def solve(i,wa,use): global ct,s,n if use>n or i==10 or wa>s: return if wa==s and use==n: ct+=1 return solve(i+1,wa,use) solve(i+1,wa+i,use+1) while 1: n,s=map(int,raw_input().split()) if n==0 and s==0: break ct=0 wa=0 solve(0,0,0) print ct
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s064849774
p00030
Wrong Answer
def f2(cnt, n, ci): if n < ci: return 0 elif n == ci and cnt > 1: return 0 elif n == ci and cnt == 1: return 1 else: v = f2(cnt - 1, n - ci, ci + 1) v += f2(cnt, n, ci + 1) return v n, s = map(int, input().split()) print(f2(n, s, 0))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s435254607
p00030
Wrong Answer
#!/usr/bin/python import os import sys import itertools def solve(f): while True: n, s = f.read_int_list() if n == 0 and s == 0: break if s > 45: return 0 def dfs(num, l): if num == 0: return 1 if len(l) == n else 0 res = 0 for i in xrange(10): if (len(l) == 0) or (max(l) < i and i <= num): li = l.copy() li.add(i) res += dfs(num-i, li) return res print dfs(s, set()) class Reader(object): def __init__(self, filename=None): self.test_mode = filename is not None self.cases = 1 self.buffer = [] if self.test_mode: with open(filename) as f: blank_flg = False for line in f: line = line.strip() if line: self.buffer.append(line) blank_flg = False else: if not blank_flg: self.cases += 1 blank_flg = True def __readline(self): return self.buffer.pop(0) if self.test_mode else raw_input() def read_int(self): return int(self.__readline()) def read_float(self): return float(self.__readline()) def read_long(self): return long(self.__readline()) def read_str(self): return self.__readline() def read_int_list(self): return [int(item) for item in self.__readline().split()] def read_float_list(self): return [float(item) for item in self.__readline().split()] def read_long_list(self): return [long(item) for item in self.__readline().split()] def read_str_list(self): return self.__readline().split() if __name__ == '__main__': filename = sys.argv[1] if len(sys.argv)>1 else None f = Reader(filename) solve(f)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s829500207
p00030
Wrong Answer
#!/usr/bin/python import os import sys import itertools def solve(f): while True: n, s = f.read_int_list() if n == 0 and s == 0: break if s > 45: print 0 continue def dfs(num, l): if num == 0: return 1 if len(l) == n else 0 res = 0 for i in xrange(10): if (len(l) == 0) or (max(l) < i and i <= num): li = l.copy() li.add(i) res += dfs(num-i, li) return res print dfs(s, set()) class Reader(object): def __init__(self, filename=None): self.test_mode = filename is not None self.cases = 1 self.buffer = [] if self.test_mode: with open(filename) as f: blank_flg = False for line in f: line = line.strip() if line: self.buffer.append(line) blank_flg = False else: if not blank_flg: self.cases += 1 blank_flg = True def __readline(self): return self.buffer.pop(0) if self.test_mode else raw_input() def read_int(self): return int(self.__readline()) def read_float(self): return float(self.__readline()) def read_long(self): return long(self.__readline()) def read_str(self): return self.__readline() def read_int_list(self): return [int(item) for item in self.__readline().split()] def read_float_list(self): return [float(item) for item in self.__readline().split()] def read_long_list(self): return [long(item) for item in self.__readline().split()] def read_str_list(self): return self.__readline().split() if __name__ == '__main__': filename = sys.argv[1] if len(sys.argv)>1 else None f = Reader(filename) solve(f)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s813016605
p00030
Wrong Answer
from itertools import combinations while True: n, s = map(int, input().split()) if n==s==0: break s = s if s < 10 else 10 print([sum(c) for c in combinations(range(s), n)].count(s))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s708932290
p00030
Wrong Answer
from itertools import combinations while True: n, s = map(int, input().split()) if n==s==0: break m = s if s < 10 else 10 print([sum(c) for c in combinations(range(m), n)].count(s))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s551615761
p00030
Wrong Answer
# coding: utf-8 # Here your code ! import math def minmax_n(n): return sum(i for i in range(0,n)), sum(i for i in range(9,9-n,-1)) def saiki(n, s, ls): ans = 0 if n==1: if s in ls: return 1 else: return 0 if s < minmax_n(n)[0] or s > minmax_n(n)[1]: return 0 for l in ls: ls_ = ls[:] ls_.remove(l) ans += saiki(n-1, s-l, ls_) return ans str = raw_input() n, s = map(int, str.split(' ')) if n==0 and s==0: exit() if s < minmax_n(n)[0] or s > minmax_n(n)[1]: print 0 print saiki(n, s, range(10))/math.factorial(n)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s821996513
p00030
Wrong Answer
import sys from itertools import combinations as c for line in sys.stdin: count = 0 k, v = map(int, line.split()) if k and v: for i in c(range(10), k): if sum(i) == v: count += 1 else: break print(count)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s291273687
p00030
Wrong Answer
a = [0,1,2,3,4,5,6,7,8,9] wa_lis = [] num = 0 def wa(n,k,m): global num if n == 9 and m == 0 and k == 0: num += 1 if n == 10: return return wa(n + 1,k - a[n],m - 1) or wa(n+1,k,m) while True: n,s = map(int,input().split()) if [n,s] == [0,0]: break wa(0,s,n) print(num) num = 0
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s304702843
p00030
Wrong Answer
def calc_combination(n, s, max_digit): if n == 1: if max_digit > s: return 0 else: return 1 if n * (n - 1) / 2 > s: return 0 total = 0 max_digit = min(s, max_digit) for i in range(n-1, max_digit): total += calc_combination(n-1, s-i, max_digit-1) return total while True: n, s = map(int, input().split()) if n == s == 0: break print(calc_combination(n, s, 9))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s692178529
p00030
Wrong Answer
while 1: n,x=map(int,input().split()) if n+x==0:break print(sum([max(0,(x-a-1)//2-max(a,x-a-1-n))for a in range(1,x//3)]))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s327583366
p00030
Wrong Answer
import itertools while True: try: a,b = map(int, raw_input().split(' ')) count = 0 if a == 0 and b == 0: break else: for com in itertools.combinations([0,1,2,3,4,5,6,7,8,9],a): if sum(com) == b: count += 1 print count except ValueError: break
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s386207724
p00030
Wrong Answer
def ksubset(n, k, i, ans): global cnt; if k == 0: if ans==s: cnt+=1 return if n == 0: return ksubset(n-1, k-1, i+1, ans+i) ksubset(n-1, k, i+1, ans) temp=raw_input() s=int(temp.split()[1]) n=int(temp.split()[0]) while (s<>0) and (n<>0): cnt=0 ksubset(10,n,0,0) print cnt temp=raw_input() s=int(temp.split()[1]) n=int(temp.split()[0])
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s947640315
p00030
Wrong Answer
def dfs(i,step,remain): if remain<0 or step<0:return 0 if remain==0 and step==0:return 1 return dfs(remain-i,i-1,step-1)+dfs(remain,i-1,step) while True: n,s=map(int,raw_input().split()) if(n==0 and s==0):break print dfs(9,n,s)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s765323384
p00030
Wrong Answer
import sys import itertools def solve(x,n,s): t=[c for c in itertools.combinations(x,n) if sum(c)==s] return len(t) x=[i for i in range(10)] for line in sys.stdin.readlines(): n,s=map(int, line.rstrip().split()) if s==0: break print solve(x,n,s)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s045010724
p00030
Wrong Answer
from __future__ import (absolute_import, division, print_function, unicode_literals) from sys import stdin from itertools import combinations for line in stdin: if line.startswith('0 0'): break num, ans = (int(s) for s in line.split()) print(sum(sum(t) == ans for t in combinations(xrange(9), num)))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s380110074
p00030
Wrong Answer
# -*- coding: utf-8 -*- import sys n = 0 s = 0 def combination(n, k): max = 2 ** n for i in xrange(max): result = [0] * n for j in xrange(n): result[j] = i >> j & 1 cnt = 0 for b in result: if b == 1: cnt += 1 if cnt == k: yield result for line in sys.stdin: l = map(int, line.strip().split()) n = l[0] s = l[1] if n == 0 and s == 0: break ans = 0 for ar in combination(9, n): sm = 0 for i in xrange(len(ar)): if ar[i] == 1: sm += i if sm == s: ans += 1 print ans
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s251351368
p00030
Wrong Answer
def dfs(n, m, s): if n == N: return 1 if s == S else 0 ans = 0 for i in range(m, 11 - n): ans += dfs(n + 1, i + 1, s + i) return ans; while 1: N, S = map(int, raw_input().split()) if not N: break print dfs(0, 0, 0)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s457752934
p00030
Wrong Answer
def f(mn, n, sm): if n == 0 and sm == 0: return 1 if mn == 10 or n == 0 or sm == 0: return 0 ct = 0 for i in range(mn, min(10, sm + 1)): ct += f(i + 1, n - 1, sm - i) return ct while True: n, sm = map(int, raw_input().split()) if n == 0 and sm == 0: break print f(0, n, sm)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s660946217
p00030
Wrong Answer
def count(target, max_size, c_size, c_num, sum): if max_size == c_size: return 1 if sum == target else 0 ans = 0 for i in range(c_num, 10): ans += count(target, max_size, c_size+1, i+1, sum+i) return ans import sys for s in sys.stdin: max_size, target = map(int, s.split()) if target == 0 or max_size == 0: break ans = count(target, max_size, 0, 0, 0) print ans
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s900461464
p00030
Time Limit Exceeded
import itertools while True: n,s=map(int,input().split()) if n==0 and s==0: break ans=0 comb=itertools.combinations(range(0,s+1),n) for c in comb: if sum(c) == s: ans +=1 print(ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s117897993
p00030
Time Limit Exceeded
import itertools while True: n,s=map(int,input().split()) if n==0 and s==0: break num=[i for i in range(0,s+1)] print(num) ans=0 comb=itertools.combinations(num,n) for c in comb: if sum(c) == s: ans +=1 print(ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s095803816
p00030
Time Limit Exceeded
import itertools while True: n,s=map(int,input().split()) if n==0 and s==0: break num=[i for i in range(0,s+1)] ans=0 comb=itertools.combinations(num,n) for c in comb: if sum(c) == s: ans +=1 print(ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s336713553
p00030
Time Limit Exceeded
# -*- coding:utf-8 -*- def kai(n): s=n ans=1 while s>1: ans*=s s-=1 return ans def main(): LIST=[] while True: try: LIST=[] ans=0 n,s=map(int,input().split()) if n==0: break #N=0なら終了 for i in range(n): LIST.append(0) for j in range(10**n): index=0 up=True flag=False count=0 #初期化 for i in LIST: if LIST.count(i)>1: flag=True #同一の数字が無いか検索 if flag: pass #あったら飛ばす else: for i in LIST: count+=i if count==s: ans+=1 #無かったら合計値が合うか見る while up: LIST[index]+=1 if LIST[index]%10==0: LIST[index]=0 up=True index+=1 else: up=False if index==len(LIST): break print(int(ans/kai(n))) except EOFError: break if __name__ == '__main__': main()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s617384707
p00030
Time Limit Exceeded
def f2(cnt, n, ci): if n < ci: return 0 elif n == ci and cnt > 1: return 0 elif n == ci and cnt == 1: return 1 else: v = f2(cnt - 1, n - ci, ci + 1) v += f2(cnt, n, ci + 1) return v while 1: n, s = map(int, input().split()) if n == 0 and s == 0: break print(f2(n, s, 0))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s783339842
p00030
Time Limit Exceeded
class Depth_First_Search_stack: def __init__(self, n, s): self.n = n self.s = s self.stack=[[i] for i in range(self.s)] self.ans = 0 def search(self): while self.stack: c = self.stack.pop() if sum(c) == self.s and len(c) == self.n: self.ans += 1 print(c) for i in range(max(c), self.s+1): if i not in c and sum(c+[i]) <= self.s and len(c+[i]) <= self.n: self.stack.append(c+[i]) if __name__ == '__main__': while 1: n, s = list(map(int, input().split(' '))) if n==0 and s==0: break DFS = Depth_First_Search_stack(n, s) DFS.search() print(DFS.ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s293995264
p00030
Time Limit Exceeded
class Depth_First_Search_stack: def __init__(self, n, s): self.n = n self.s = s self.stack=[[i] for i in range(self.s)] self.ans = 0 def search(self): while self.stack: c = self.stack.pop() if sum(c) == self.s and len(c) == self.n: self.ans += 1 print(c) for i in range(self.s-max(c) + 1): if max(c)<i and sum(c+[i]) <= self.s and len(c+[i]) <= self.n: self.stack.append(c+[i]) if __name__ == '__main__': while 1: n, s = list(map(int, input().split(' '))) if n==0 and s==0: break DFS = Depth_First_Search_stack(n, s) DFS.search() print(DFS.ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s807045341
p00030
Time Limit Exceeded
def div(n,m): try: return n/m except ZeroDivisionError: return 0 def degit(n, m): r = [] b = -1 for i in xrange(m): s = div(n%(10**(i+1)),(10**i)) if(b<s): b = s r.append(s) if(len(r) == m): return r while True: (n, s) = [int(i) for i in raw_input().split()] if((0,0) == (n,s)): break ans = 0 for i in xrange(10**n): r = degit(i,n) if(r==None): continue if(len(r)!=len(list(set(r)))): continue if(reduce(lambda x,y:x+y,r) == s): ans += 1 print ans
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s433219923
p00030
Memory Limit Exceeded
#!/usr/bin/env python # -*- coding: utf-8 -*- import itertools S = [] N = [] while True: n,s = map(int,input().split(" ")) if s == 0 and n == 0: break else: N.append(n) S.append(s) for i in range(0,len(S)): sumMap = list(map(sum,list(itertools.combinations(range(0,S[i]+1),N[i])))) print(sum([1 for j in range(0,len(sumMap)) if sumMap[j] == S[i]]))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s526962090
p00030
Memory Limit Exceeded
from itertools import combinations as C while True: n, s = map(int, input().split()) if n == 0: break print([sum(c) == s for c in C(range(s+1), n)])
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s178930722
p00030
Accepted
from itertools import combinations while True: n,s = [int(i) for i in input().split()] if (n, s) == (0, 0): break ans = 0 for num in combinations(range(10),n): if sum(num) == s: ans += 1 print(ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s117020169
p00030
Accepted
import itertools l=range(10) while True: n,s=map(int, raw_input().split()) if n==0: break cnt=0 for i in list(itertools.combinations(l,n)): if s == sum(i): cnt+=1 print cnt
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s966532907
p00030
Accepted
import itertools while True: n, s = map(int, input().split(' ')) if n + s == 0: break ans = 0 for i in itertools.combinations(range(10), n): if sum(i) == s: ans += 1 print(ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s064129107
p00030
Accepted
ans = 0 def count(use, sum, n, s): global ans if(sum > s or n < 0): return; if(n == 0 and s == sum): ans += 1 else: for i in range(use + 1, 10): count(i, sum + i, n - 1, s) while(True): n = map(int, raw_input().split()) ans = 0 if(n[0] == 0 and n[1] == 0): break count(-1, 0, n[0], n[1]) print(ans)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s133197421
p00030
Accepted
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import itertools for s in sys.stdin: d = map( int, s.split() ) if d == [ 0,0 ]: break n, s = d[0], d[1] lis = list(itertools.combinations(range(10),d[0])) print sum( [ 1 for e in lis if sum(e) == d[1] ] )
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s144391657
p00030
Accepted
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys import itertools class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break ans = 0 # self.dfs(0, 0, [], n, s) # for i in range(10): # for j in range(10): # for k in range(10): # if i >= j or j >= k or i >= k: # continue # if i + j + k == s: # print i, j, k # ans += 1 for e in itertools.combinations(range(10), n): if sum(e) == s: ans += 1 print ans return None # def dfs(self, num, sumNum, rec, n, s): # print num, sumNum, rec, n, s # if num == n: # if sumNum == s: # self.ans += 1 # else: # for i in range(s): # if not i in rec and sumNum + i <= s: # self.dfs(num + 1, sumNum + i, rec + [i], n, s) if __name__ == '__main__': h = Hoge() h.func()
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s190422142
p00030
Accepted
#!/usr/bin/env python # -*- coding: utf-8 -*- import itertools S = [] N = [] while True: n,s = map(int,input().split(" ")) if s == 0 and n == 0: break else: N.append(n) S.append(s) for i in range(0,len(S)): sumMap = list(map(sum,list(itertools.combinations(range(0,10),N[i])))) print(sum([1 for j in range(0,len(sumMap)) if sumMap[j] == S[i]]))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s261249351
p00030
Accepted
import sys f = sys.stdin import itertools while True: n, s = map(int, f.readline().split()) if n == 0: break print(sum(1 for nums in itertools.combinations([i for i in range(10)], n) if sum(nums) == s))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s221423275
p00030
Accepted
import sys import itertools for line in sys.stdin: (n, s) = map(int, line.split(" ")) if n == 0 and s == 0: break cnt = 0 for v in itertools.combinations(range(10), n): cnt += sum(v) is s print(cnt)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s610725084
p00030
Accepted
def sum_count(n,s,r): count = 0 if n==1: if (r<=s and s<=9): return 1 else: return 0 else: return sum([sum_count(n-1,s-i,i+1) for i in range(r,9)]) while True: n,s=map(int,raw_input().split(" ")) if n==0 and s==0: break print sum_count(n,s,0)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s574125067
p00030
Accepted
def dfs(pos, t, sum): global cnt if t == n: if sum == s: cnt += 1 return if pos > 9: return dfs(pos+1, t, sum) dfs(pos+1, t+1, sum + pos) while True: n, s = map(int, raw_input().split()) if n==0 and s==0: break cnt = 0 dfs(0, 0, 0) print cnt
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s189725012
p00030
Accepted
dp = [[0] * 101 for _ in range(11)] def dfs(n, p, s): if p == 10: return for i in range(n, 10): dp[p][s + i] += 1 dfs(i + 1, p + 1, s + i) dfs(0, 0, 0) while True: l = map(int, raw_input().split()) if l[0] == 0 and l[1] == 0: break print dp[l[0] - 1][l[1]]
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s190950609
p00030
Accepted
def solve(n, s, low): if n == 0: return 1 if s == 0 else 0 res = 0 for i in range(low,10): if s - i < 0: break res += solve(n-1, s-i, i+1) return res while True: n, s = map(int, raw_input().split(' ')) if n == 0: break print solve(n, s, 0)
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s810353316
p00030
Accepted
def move(move_count, add, flag): for i in range(move_count): n_lis.append(num_lis[add+i]) if flag == n: calculate() del n_lis[-1] else: move(move_count-i-1, add+i+1, flag+1) del n_lis[-1] def calculate(): global count if sum(n_lis) == s: count += 1 while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break num_lis = [0,1,2,3,4,5,6,7,8,9] n_lis = [] count = 0 move(10,0,1) print count
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s537594492
p00030
Accepted
def move(move_count, current, flag): for i in range(move_count): n_lis.append(num_lis[current+i]) if flag == n: calculate() del n_lis[-1] else: move(move_count-i-1, current+i+1, flag+1) del n_lis[-1] def calculate(): global count if sum(n_lis) == s: count += 1 while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break num_lis = [0,1,2,3,4,5,6,7,8,9] n_lis = [] count = 0 move(10,0,1) print count
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s854212476
p00030
Accepted
def move(move_count, current, flag): for i in range(move_count): n_lis.append(num_lis[current+i]) if flag == n: calculate() del n_lis[-1] else: move(move_count, current+i+1, flag+1) move_count -= 1 del n_lis[-1] def calculate(): global count if sum(n_lis) == s: count += 1 while True: n, s = map(int, raw_input().split()) if n == 0 and s == 0: break num_lis = [0,1,2,3,4,5,6,7,8,9] n_lis = [] count = 0 move(10-n+1,0,1) print count
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s959189456
p00030
Accepted
import itertools l=range(10) while 1: n,s=map(int, raw_input().split()) if n==0: break cnt=0 for i in list(itertools.combinations(l,n)): if sum(i)==s: cnt+=1 print cnt
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s536681635
p00030
Accepted
import itertools while True: n,s = map(int,raw_input().split()) if n == 0 and s == 0: break count = 0 num = list(itertools.combinations(xrange(10), n)) for var in num: if sum(var) == s: count += 1 print count
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s737007900
p00030
Accepted
def f(n,s,x): if n == s == 0: return 1 elif n == 0 or x == 0: return 0 else: a = 0 for i in range(x): a += f(n-1,s-i,i) return a while True: n,s = map(int,input().split()) if n == s == 0: break print(f(n,s,10))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s813425252
p00030
Accepted
from math import * PI = 3.1415926535898 def dfs(i, su, cnt, s): if su == s and cnt == 0: return 1 if i == 10 or cnt == 0: return 0 return dfs(i+1, su, cnt, s) + dfs(i+1, su+i, cnt-1, s) while True: try: n, s = map(int, raw_input().strip().split()) if n == 0 and s == 0: break print dfs(0, 0, n, s) except EOFError: break
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s338451369
p00030
Accepted
cnt = 0 li = range(10) n, s = 0, 0 def dfs(i, num, total): global cnt if i <= 10 and num == n and total == s: #answer is finded cnt += 1 return; if i >= 10 or num > n or total > s: #out of range return; #when use i dfs(i+1, num+1, total+i) #when skip i dfs(i+1, num, total) while True: n, s = map(int, raw_input().split()) if n == s == 0: break cnt = 0 dfs(0, 0, 0) print cnt
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s091950983
p00030
Accepted
def decSum(n, sm, mn): #print(n,sm,mn) if mn + n > 10 : return 0 elif sum(range(mn, mn + n)) > sm or sum(range(10 - n, 10)) < sm: return 0 elif n == 1: return 1 else: a = 0 for i in range(mn, 10 if sm >= 10 else sm): a += decSum(n - 1, sm - i, i + 1) return a while True: n, sm = map(int, input().split()) if n == 0: break print(decSum(n, sm, 0))
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
s947735862
p00030
Accepted
#encoding=utf-8 while True: x, num = map(int,raw_input().split()) if x == num == 0: break count = 0 for a in xrange(10): if num == a and x == 1: count += 1 if x > 1: for b in xrange(a + 1,10): if num == a+b and x == 2: count += 1 if x > 2: for c in xrange(b + 1,10): if num == a+b+c and x == 3: count += 1 if x > 3: for d in xrange(c + 1,10): if num == a+b+c+d and x == 4: count += 1 if x > 4: for e in xrange(d + 1,10): if num == a+b+c+d+e and x == 5: count += 1 if x > 5: for f in xrange(e + 1,10): if num == a+b+c+d+e+f and x == 6: count += 1 if x > 6: for g in xrange(f + 1,10): if num == a+b+c+d+e+f+g and x == 7: count += 1 if x > 7: for h in xrange(g + 1,10): if num == a+b+c+d+e+f+g+h and x == 8: count += 1 if x > 8: for i in xrange(h + 1,10): if num == a+b+c+d+e+f+g+h+i and x == 9: count += 1 print count
3 6 3 1 0 0
3 0
<H1>整数の和</H1> <p> 0 から 9 の数字から異なる <var>n</var> 個の数を取り出して合計が <var>s</var> となる組み合わせの数を出力するプログラムを作成してください。<var>n</var> 個の数はおのおの 0 から 9 までとし、1つの組み合わせに同じ数字は使えません。たとえば、<var>n</var> が 3 で <var>s</var> が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、<br/> <br/> 1 + 2 + 3 = 6<br/> 0 + 1 + 5 = 6<br/> 0 + 2 + 4 = 6<br/> <br/> の 3 通りとなります。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (1 &le; <var>n</var> &le; 9) と <var>s</var> (0 &le; <var>s</var> &le; 100) が1つのスペースで区切られて1行に与えられます。<var>n</var> と <var>s</var> が共に 0 のとき入力の最後とします(この場合は処理せずにプログラムを終了する)。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 3 6 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>