精進?
PKUをPOJと呼ばないのはPKUの正式名称がPKU judgeonlineだからなんですね。。。
3994
やるだけ
#include <cstdio> int main() { int n, cn=1; while (scanf("%d",&n)) { if (!n) break; bool even=false; n *= 3; if (n % 2 == 0) even = true; if (even) n /= 2; else n = (n + 1) / 2; n *= 3; n /= 9; if (even) printf("%d. even %d\n",cn++,n); else printf("%d. odd %d\n",cn++,n); } }
3982
多倍長だからと弱気になって他人のコード写したorz
いや、引数がポインタ参照なのなんでかよくわからないけど・・・
#include <string> #include <iostream> #include <algorithm> using namespace std; string ret; string add(const string &a, const string &b) { ret=""; int as=a.size(), bs=b.size(); int c=0; for (int i=0; i<max(as,bs); i++) { int t=c; if (i<as) t+=a[as-i-1]-'0'; if (i<bs) t+=b[bs-i-1]-'0'; c=t/10; t%=10; ret+=t+'0'; } if (c) ret+=c+'0'; reverse(ret.begin(), ret.end()); return ret; } int main() { string dp[100]; while (cin>>dp[0]>>dp[1]>>dp[2]) { for (int i=3; i<100; i++) { dp[i]=add(dp[i-1],add(dp[i-2],dp[i-3])); } cout<<dp[99]<<endl; } }
ちなみに反省して多倍長ライブラリをこれ参考に作成なう。
途中経過
#include <iostream> #include <algorithm> #include <string> using namespace std; string ret; string add(const string &a, const string &b) { ret=""; int as=a.size(),bs=b.size(); int c=0; for (int i=0; i<max(as,bs); i++) { int t=c; if (i<as) t+=a[as-i-1]-'0'; if (i<bs) t+=b[bs-i-1]-'0'; c=t/10; t%=10; ret+=t+'0'; } reverse(ret.begin(), ret.end()); return ret; } string dec(const string &a, const string &b) { ret=""; int as=a.size(),bs=b.size(); int c=0; for (int i=0; i<max(as,bs); i++) { int t=c; if (i<as) t+=a[as-i-1]-'0'; if (i<bs) t-=b[bs-i-1]-'0'; if (t<0) { c=-1; t+=10; } else { c=0; } ret+=t+'0'; } if (c<0) ret+='-'; reverse(ret.begin(), ret.end()); return ret; } string mul(const string &a, const string &b) { ret=""; int as=a.size(),bs=b.size(); int c=0; } void test(string a, string b) { cout << "a+b: " << add(a,b) << endl; cout << "a-b: " << dec(a,b) << endl; } int main() { string a, b; cin>>a>>b; test(a,b); }
3632
よく見たらやるだけ。
テストケース熟読必須。
#include <cstdio> #include <algorithm> using namespace std; int main() { int t; scanf("%d",&t); int n; for (int ix=0; ix<t; ix++) { scanf("%d",&n); int store[n]; for (int i=0; i<n; i++) scanf("%d",&store[i]); sort(store, store+n); printf("%d\n",(store[n-1]-store[0])*2); } }
sortじゃなくても良かったんですが、勘違いでそこまでかいちゃってたのでそのまま使った。