哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題-2011年
Posted on 2011-09-25 19:33 Uriel 閱讀(277) 評論(0) 編輯 收藏 引用 所屬分類: 考研&保研復(fù)試上機(jī)題貌似。。哈工大的機(jī)試題都極其的水。。。
1. 數(shù)組逆置
本來想寫個遞歸的。。但是覺得實在是畫蛇添足。。
//2011年哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題 數(shù)組逆置
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char s[1000];

int main() {
int i;
while(gets(s) != NULL) {
for(i = strlen(s) - 1; i >= 0; --i) putchar(s[i]);
puts("");
}
return 0;
}
2. 最大公約數(shù)
大水不解釋
//2011年哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題 最大公約數(shù)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;

int gcd(int a, int b) {
if(!b) return a;
return gcd(b, a % b);
}

int main() {
int a, b;
while(~scanf("%d %d", &a, &b)) {
if(a < b) swap(a, b);
printf("%d\n", gcd(a, b));
}
return 0;
}
3. 眾數(shù)
memset不小心開到while外面去了。。WA*1
//2011年哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題 眾數(shù)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int fg[20];

int main() {
int mx, mk, a, i;
while(~scanf("%d", &a)) {
memset(fg, 0, sizeof(fg));
fg[a]++;
for(i = 1; i < 20; ++i) {
scanf("%d", &a);
fg[a]++;
}
mx = 0;
for(i = 1; i <= 10; ++i) {
if(fg[i] > mx) {
mx = fg[i];
mk = i;
}
}
printf("%d\n", mk);
}
return 0;
}
1. 數(shù)組逆置
本來想寫個遞歸的。。但是覺得實在是畫蛇添足。。
//2011年哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題 數(shù)組逆置
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char s[1000];
int main() {
int i;
while(gets(s) != NULL) {
for(i = strlen(s) - 1; i >= 0; --i) putchar(s[i]);
puts("");
}
return 0;
}2. 最大公約數(shù)
大水不解釋
//2011年哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題 最大公約數(shù)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int gcd(int a, int b) {
if(!b) return a;
return gcd(b, a % b);
}
int main() {
int a, b;
while(~scanf("%d %d", &a, &b)) {
if(a < b) swap(a, b);
printf("%d\n", gcd(a, b));
}
return 0;
}3. 眾數(shù)
memset不小心開到while外面去了。。WA*1
//2011年哈爾濱工業(yè)大學(xué)計算機(jī)研究生機(jī)試題 眾數(shù)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int fg[20];
int main() {
int mx, mk, a, i;
while(~scanf("%d", &a)) {
memset(fg, 0, sizeof(fg));
fg[a]++;
for(i = 1; i < 20; ++i) {
scanf("%d", &a);
fg[a]++;
}
mx = 0;
for(i = 1; i <= 10; ++i) {
if(fg[i] > mx) {
mx = fg[i];
mk = i;
}
}
printf("%d\n", mk);
}
return 0;
}



