ZeroJudge:102-2 資訊第一次小考參考解答 (a040)*************** 第一題 *************** //a040: 阿姆斯壯數 by Snail #include using namespace std; int main () { int i, j, a, b, arm[21]={1,2,3,4,5,6,7,8,9,153,370,371,407,1634,8208,9474,54748,92727,93084,548834,1000001}; //int k, r, n, x, e, d[7], narm=0; //求陣列中的值 //for (i=1; i<=1000000; i++) { // r = i; // for (e=0; r; e++) { // d[e] = r % 10; // r /= 10; // } // n = 0; // for (j=0; j> a >> b) { for (i=0; arm[i] using namespace std; int main (){ int s,i,a[100],b,t=1; while(cin>>s, s>=0){ for(i=0; i<12; i++) cin>>a[i]; cout << "Case " << t++ << ":" << endl; for(i=0; i<12; i++){ cin>>b; if(b>s) cout << "No problem. :(" << endl; else { cout << "No problem! :D" << endl; s -= b; } s += a[i]; } } } (d212)*************** 第三題 *************** //d212. 東東爬階梯 by Snail #include using namespace std; int main () { unsigned long long s[93] = {1, 1}; int i, n; for (i=2; i<=92; i++) s[i] = s[i-1] + s[i-2]; i = 0; while (cin >> n) i=max(i,n),cout << s[n] << endl; } (c032)*************** 第四題 *************** //382 - Perfection (by Snail) #include #include #include using namespace std; int main () { int s, n, f; string output[3] = {"DEFICIENT", "PERFECT", "ABUNDANT"}; cout << "PERFECTION OUTPUT\n"; while (cin >> n, n) { s = n>1; for (f=2; f*f=n)+(s>n)] << endl; } cout << "END OF OUTPUT\n"; } (d117)*************** 第五題 *************** //10924 - Prime Words (by Snail) #include #include using namespace std; int main () { int i, n, n2; string s; while (cin >> s) { n = 0; for (i=0; i<(int)s.size(); i++) n += (s[i] < 'a' ? s[i] - 38 : s[i] - 96); for (i=2; n%i && i*i<=n; i++); //求第一個 <= 平方根的因數 cout << (i*i > n ? "It is a prime word.\n" : "It is not a prime word.\n"); } } (b255)*************** 第六題 *************** //D. 跑跑卡丁車 -- 2009 NPSC 高中組決賽 by Snail #include #include #include using namespace std; struct racer { string n, t; int sn; } r[100000]; bool timelt (racer a, racer b) {return a.t < b.t;} bool snlt (racer a, racer b) {return a.sn < b.sn;} int main () { int n, i, k, h, m; char ch; while (cin >> n, n) { for (i=0; i> r[i].n >> r[i].t; r[i].sn = i; //s(erial) n(umber)--序號 } sort (r, r+n, timelt); //依時間由小到大排序 for (k=n/3; k #include #include using namespace std; string a[100000], b[100000], c[100000]; int main () { int n, i, j, m; while (cin >> n, n) { cout << "LIST START\n"; for (i=0; i> a[i] >> b[i], c[i] = b[i]; sort(c, c+n); m = n/3 - 1; for (i=0; i