2010年哈爾濱工業大學電腦研究生機試真題

來源:互聯網
上載者:User

標籤:

題目串連:點擊開啟連結


解題思路:

簡單暴力

完整代碼:

#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年哈爾濱工業大學電腦研究生機試真題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.