Aizu Online Judge(AOJ)の過去問から、その提出コードの解答例です。
・問題 "Sum of Integers"
https://onlinejudge.u-aizu.ac.jp/problems/0030
・整数の和
僕が作成、提出したコードは、以下のとおりです。
・Aizu Online Judge in C++ #Volume0 - 0030 : Sum of Integers
/* Aizu Online Judge in C++ #Volume0 - 0030 : Sum of Integers https://onlinejudge.u-aizu.ac.jp/problems/0030 提出コードの解答例 https://neguse-atama.hatenablog.com */ #include<bits/stdc++.h> using namespace std; using ll=long long; int main(void){ ll n,s; while(cin>>n>>s,n){ ll ans=0; for(ll i=0;i<1024;i++){ ll a=0,b=0; for(ll j=0;j<10;j++){ if((i>>j) & 1){ a+=j; b++; } } if(a==s && b==n){ ans++; } } cout<<ans<<endl; } return 0; }
設問の出典は、プログラミング問題のオンライン採点システム「Aizu Online Judge(AOJ)」です。
http://judge.u-aizu.ac.jp/onlinejudge/