码迷,mamicode.com
首页 > 其他好文 > 详细

2010年哈尔滨工业大学计算机研究生机试真题

时间:2015-04-05 13:24:23      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

题目连接:点击打开链接


解题思路:

简单暴力

完整代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
int n;
int a[300];
 
bool check(int key)
{
    set<int> s;
    s.clear();
    for(int i = 1 ; i < key ; i ++)
    {
        if(key % i == 0)
            s.insert(i);
    }
    set<int>::iterator it;
    int sum = 0;
    for(it = s.begin() ; it != s.end() ; it++)
    {
        sum += *it;
    }
    if(sum == key)  return true;
    else    return false;
}
 
int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    while(cin >> n)
    {
        int a[1001];
        int cnt = 0;
        for(int i = 1 ; i <= n ; i ++)
        {
            if(check(i))
            {
                a[cnt++] = i;
            }
        }
        for(int i = 0 ; i < cnt ; i ++)
            printf("%d%s" , a[i] , i == cnt - 1 ? "\n" : " ");
    }
}
 

题目连接:点击打开链接


解题思路:

JAVA大法好

完整代码:

import java.math.BigInteger;
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] argvs){
        Scanner cin = new Scanner(System.in);
        String a;
        int n;
        while(cin.hasNext()){
            a = cin.next();
            n = cin.nextInt();
            BigInteger sum = new BigInteger("0");
            for(int i = 1; i <= n ; i ++){
                String temp = "";
                for(int j = 1 ; j <= i ; j ++){
                    temp += a;
                }
                BigInteger k = new BigInteger(temp);
                sum = sum.add(k); 
            }
            System.out.println(sum);
        }
    }   
}
 

题目连接:点击打开链接


解题思路:

排序

完整代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int a[300];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    while(cin >> n)
    {
        for(int i = 0 ; i < n ; i ++)
            cin >> a[i];
        int x;
        cin >> x;
        int flag = 0;
        for(int i = 0 ; i < n ; i ++)
        {
            if(a[i] == x)
            {
                cout << i << endl;
                flag = 1;
                break;
            }
        }
        if(!flag)
            cout << "-1" << endl;
    }
}

题目连接:点击打开链接


解题思路:

暴力

完整代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int INF = 1000000000;
int n;
int a[30];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    while(cin >> n)
    {
        int maxx = -INF , minn = INF , maxpos , minpos;
        for(int i = 0 ; i < n ; i ++)
        {
            cin >> a[i];
            if(a[i] > maxx)
            {
                maxx = a[i];
                maxpos = i;
            }
            if(a[i] < minn)
            {
                minn = a[i];
                minpos = i;
            }
        }
        swap(a[maxpos] , a[minpos]);
        for(int i = 0 ; i < n ; i ++)
            printf("%d%s" , a[i] , i == n - 1 ? "\n" : " ");
    }
}

题目连接:点击打开链接


解题思路:

排序

完整代码:

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
 
#pragma comment(linker, "/STACK:102400000,102400000")
 
typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;
 
/** Constant List .. **/ //{
 
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
 
bool cmp(char a , char b)
{
    return a < b;
}
char a[1000001];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    string s;
    while(cin >> s)
    {
        int len = s.length();
        for(int i = 0 ; i < len ; i ++)
            a[i] = s[i];
        a[len] = '\0';
        sort(a, a + len , cmp);
        for(int i = 0 ; i < len ;i ++)
            cout << a[i];
        cout << endl;
    }
}


2010年哈尔滨工业大学计算机研究生机试真题

标签:

原文地址:http://blog.csdn.net/u013447865/article/details/44886889

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!