The Beijing Institute of Technology re-examination machine --2002

1, a person has 80 cents of five stamps, stamp four $ 1, 80 cents of postage stamp 1 yuan 6, these stamps are a number of sheets or how much postage you can get different?
#include <iostream>
#include <set>
using namespace std;
int main() {
    set<int> s;
    int i, j, k;
    for(i = 0; i <= 5; i++) {
        for(j = 0; j <= 4; j++) {
            for(k = 0; k <= 6; k++) {
                s.insert(8 * i + 10 * j + 18 * k);
            }
        }
    }
    cout << s.size() - 1;
    return 0;
}
2, a value for n, recursive function evaluated at various locations in Triangle, follows the form of the graphic printout. For example: when n = 6.
      1
    1  1
   1 2  1
  1 3 3  1
 1 4  6  4 1
1 5 10 10 5 1
#include <iostream>
using namespace std;

int yh(int x, int y) {
    if(x == y || y == 1) return 1;
    else return yh(x - 1, y - 1) + yh(x - 1, y);
}

int main() {
    int n;
    while(cin >> n) {
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                cout << " ";
            }
            for(int j = 0; j <= i; j++) {
                cout << yh(i + 1, j + 1) << " ";
            }
            cout << endl;
        }
    }
    return 0;
}
 3, does not exceed the number of print all n (n <256), which has a square symmetric properties. The 11 * 11 = 121.
#include <iostream>
using namespace std;

bool sym(int n) {
    int m = n;
    int a[20], i = 0, sum = 0, x = 1;
    while(m) {
        a[i++] = m % 10;
        m /= 10;
    }
    for(int j = i - 1; j >= 0; j--) {
        sum += a[j] * x;
        x *= 10;
    }
    return sum == n;
}
int main() {
    for(int i = 1; i <= 256; i++) {
        if(sym(i * i)) cout << i << " ";
    }
    return 0;
}
4, a write request Fibonacci odd columns recursive function, a value for n, the recursive function using, as an output pattern. For example: n = 6, when
          0
        0 1 1
      0 1 1 2 3
    0 1 1 2 3 5 8
  0 1 1 2 3 5 8 13 21
0 1 1 2 3 5 8 13 21 34 55
#include <iostream>
using namespace std;

int fib(int n) {
    if(n == 0) return 0;
    else if(n == 1) return 1;
    return fib(n - 1) + fib(n - 2);
}

int main() {
    int n;
    while(cin >> n) {
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                cout << " ";
            }
            for(int j = 0; j < 2 * i + 1; j++) {
                cout << fib(j) << " ";
            }
            cout << endl;
        }
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/ache/p/12520088.html