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

题目连接:点击打开链接

解题思路:

简单暴力

完整代码:

#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;
    }
}
时间: 2024-08-11 03:10:19

2010年哈尔滨工业大学计算机研究生机试真题的相关文章

字符串去特定字符-2009年哈尔滨工业大学计算机研究生机试真题

题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和字符c. 输出: 对于每组输入,输出去除c字符后的结果. 样例输入: heallo    a 样例输出: hello 解题代码: 解法1:使用两个数组, 第二个数组存储去掉特定字符的字符串 #include <stdio.h> int main(){ char arr[200]; char arrNew[200]; char focus; while (scanf("%

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

题目描述: 输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1). 输入: 测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x. 输出: 对于每组输入,请输出结果. 样例输入: 2    1 3    0 样例输出: -1 解题代码: #include <stdio.h> int main(){ int n; int array[200]; while (scanf("%d"

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

题目连接:点击打开链接 解题思路: 暴力 完整代码: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <set> using namespace std; const int INF = 1000000000; string s; int main() { #ifdef DoubleQ freopen("in.t

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

题目连接:点击打开链接 解题思路: 模拟 完整代码: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <set> using namespace std; const int INF = 1000000000; const int maxn = 10001; char a[maxn] , b[maxn]; void MyS

判断三角形类型-2009年哈尔滨工业大学计算机研究生机试真题

题目描述: 给定三角形的三条边,a,b,c.判断该三角形类型. 输入: 测试数据有多组,每组输入三角形的三条边. 输出: 对于每组输入,输出直角三角形.锐角三角形.或是钝角三角形. 样例输入: 3 4 5 样例输出: 直角三角形 解题代码: #include <stdio.h> int main(){ int arr[3]; int temp; while (scanf("%d%d%d",&arr[0],&arr[1],&arr[2] ) != EO

九度机试 题目1165:字符串匹配 2008年北京航空航天大学计算机研究生机试真题

题目1165:字符串匹配 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2497 解决:858 题目描述: 读入数据string[ ],然后读入一个短字符串.要求查找string[ ]中和短字符串的所有匹配,输出行号.匹配字符串.匹配时不区分大小写,并且可以有一个用中括号表示的模式匹配.如"aa[123]bb",就是说aa1bb.aa2bb.aa3bb都算匹配. 输入: 输入有多组数据. 每组数据第一行输入n(1<=n<=1000),从第二行开始输入n个字符串(

考察数据类型的掌握---题目1166:迭代求立方根 (2009年北京航空航天大学计算机研究生机试真题)

题目描述: 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 + x/(3*y(n)*y(n)),其中y0=x.求给定的x经过n次迭代后立方根的值. 输入: 输入有多组数据.每组一行,输入x n. 输出: 迭代n次后的立方根,double精度,保留小数点后面六位. 样例输入: 3000000 28 样例输出: 144.224957 #include "stdio.h" int main(int argc, char* argv[]) {     long n;     dou

2000年华中科技大学计算机研究生机试真题 阶乘

题目1179:阶乘 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4993 解决:1464 题目描述: 输入n,求y1=1!+3!+...m!(m是小于等于n的最大奇数)y2=2!+4!+...p!(p是小于等于n的最大偶数). 输入: 每组输入包括1个整数:n 输出: 可能有多组测试数据,对于每组数据,输出题目要求的y1和y2 样例输入: 4 样例输出: 7 26 来源: 2000年华中科技大学计算机研究生机试真题 #include <iostream> #include <

题目1117:整数奇偶排序 (2008年北京大学图形实验室计算机研究生机试真题)

题目描述: 输入10个整数,彼此以空格分隔.重新排序以后输出(也按空格分隔),要求:1.先输出其中的奇数,并按从大到小排列:2.然后输出其中的偶数,并按从小到大排列. 输入: 任意排序的10个整数(0-100),彼此以空格分隔. 输出: 可能有多组测试数据,对于每组数据,按照要求排序后输出,由空格分隔. 样例输入: 4 7 3 13 11 12 0 47 34 98 样例输出: 47 13 11 7 3 0 4 12 34 98 提示: 1. 测试数据可能有很多组,请使用while(cin>>