2011---2013年杭电计算机历年研究生复试---笔试编程
生活随笔
收集整理的這篇文章主要介紹了
2011---2013年杭电计算机历年研究生复试---笔试编程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、輸入三個正整數A、B、C(0<A、B、C<1000),判斷這三個數能不能構成一個三角形。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <iostream> #include <algorithm> using namespace std;int main(void) {int a[3], i;for(i = 0; i < 3; ++i)scanf("%d", &a[i]);sort(a, a + 3); //排序后,直接用兩個最小數的和與第三個數進行比較就可以了if(a[0] + a[1] > a[2])printf("It is a triangle\n");elseprintf("It is not a triangle\n");return 0; }
2、有個人從2003年1月1日開始,三天打魚兩天曬網,請輸入月份、日期,問在當年的某一天他是在打魚還是在曬網。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>int main(void) {int i, m, d, sum;int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};scanf("%d %d", &m, &d);for(i = 1, sum = 0; i < m; ++i)sum += month[i]; sum = sum + d - 1; //計算輸入的某一天距離1月1日的間隔天數if(sum % 5 < 3)printf("打漁\n");elseprintf("曬網\n");return 0; }
3、丑數是這樣定義的:如果一個正整數的素因子只包含 2、3、5、7四種,則它被稱為丑數。以下數列 1, 2, 3,4, 5,6,7,8,9, 10,12,14,15,16,18, 20, 21,24,25, 27.......... 就顯示了前20個丑數。
給出一個正整數N,判斷這個數是否為丑數。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>bool IsUgly(int number) {while(number % 7 == 0) //輸入的整數分別與2、3、5、7進行循環除法運算(在取模運算為0的情況下)number /= 7;while(number % 5 == 0)number /= 5;while(number % 3 == 0)number /= 3;while(number % 2 == 0)number /= 2;return (number == 1) ? true : false; }int main(void) {int n;scanf("%d", &n);if(IsUgly(n))printf("Yes\n");elseprintf("No\n");return 0; }
2012年杭電計算機研究生復試---筆試編程
1、輸入一個十進制的數,把它轉成十六進制。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>int main(void) {int num, i, j;char str[100];i = 0;scanf("%d" , &num);while(num != 0){j = num % 16;if(j < 10)str[i++] = j + '0';elsestr[i++] = j - 10 + 'A';num /= 16;}if(i == 0)printf("0\n");else{for(j = i - 1; j >= 0; --j)printf("%c", str[j]);printf("\n");}return 0; }
2、貪吃蛇,給你一個50X50的表格,貪吃蛇初始化在某個位置,自身長度20格,頭往四個方向移動,每次移動一格,判斷是成功、出界還是撞到自己,具體的題目是用英文描述的,大概意思就是這樣。輸入第一行為移動的步數,第二行為這些步數的方向,輸出判斷。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>#define WORM_LENGTH 20int main(void) {short h[WORM_LENGTH], v[WORM_LENGTH]; // 用于記錄蟲子每一節的位置,(v[0], h[0])是頭部short newHead_v, newHead_h; // 移動一步后頭部的新位置int i, j, steps;int ranIntoItself, ranOffBoard;char moves[1000];scanf("%d", &steps); // 讀入每個測試用例要移動的步數while (steps != 0) {scanf("%s", moves); // 讀入移動方向字符串// 蟲子的初始位置for (i = 0; i < WORM_LENGTH; ++i){h[i] = 30 - i;v[i] = 25;}ranIntoItself = ranOffBoard = 0;for (i = 0; i < steps; ++i){// 計算移動一步后頭部的位置newHead_h = h[0];newHead_v = v[0];switch (moves[i]){case 'E':newHead_h++;break;case 'S':newHead_v++;break;case 'W':newHead_h--;break;case 'N':newHead_v--;break;}// 判斷是否碰到自己的身體for (j = 1; j < WORM_LENGTH - 1; ++j) // 由于移動后尾部位置已前移一格,所以是WORM_LENGTH - 1{if (newHead_h == h[j] && newHead_v == v[j]) {ranIntoItself = 1;break;}}// 判斷是否碰到邊緣if (newHead_h == 0 || newHead_h == 49 || newHead_v == 0 || newHead_v == 49)ranOffBoard = 1;if (ranIntoItself || ranOffBoard)break;// 移動蟲子除頭部后的幾節for (j = WORM_LENGTH - 1; j > 0; --j){h[j] = h[j - 1];v[j] = v[j - 1];}h[0] = newHead_h;v[0] = newHead_v;}// 輸出移動后的狀態if (ranIntoItself)printf("The worm ran into itself on move %d\n", i + 1);else if (ranOffBoard)printf("The worm ran off the board on move %d\n", i + 1);elseprintf("The worm successfully made all %d moves\n", steps);// 繼續讀下一字符串scanf("%d", &steps);}return 0; }
2012杭電復試專業英語筆試翻譯題
請將下面的短文翻譯成中文。
? ? ?Java is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose,concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere"(WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java is currently one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users.
? ? ?The original Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.
參考答案:
? ? ? Java是Sun微系統公司(該公司已并入Oracle公司)的 James Gosling最初開發的一種程序設計語言,在1995年作為Sun公司Java平臺的核心組件發布。這種語言繼承了C和C++的很多語法格式,但具有更簡單的對象模型和更少的低層機制。Java應用程序通常被編譯成字節碼(類文件),可以在任意的Java虛擬機(JVM)上運行而忽視計算機的體系結構。Java是一種通用的、并發的、基于類的和面向對象的語言,特別地設計成具有盡可能低的實現依賴性。該語言的思想是讓應用程序開發者“一次編寫,到處運行”(WORA),這意味著在一個平臺上運行的代碼不需要重新編譯就可以運行在另一個平臺。如今Java已成為在用的最普遍的程序設計語言之一,特別是用于編寫客戶機-服務器的web應用程序,據報道有1000萬的使用者。?
? ? ?最初的Java編譯器、虛擬機和類庫是由Sun公司從1995開始開發的。在2007年5月,遵照Java社區進程(JCP)的要求,Sun在GNU通用公開許可協議(GPL)的規定下重新發布了它的大部分Java技術許可。第三方組織也完成了這些Sun技術的替代實現,比如GNU的Java翻譯器和GNU Classpath等。
?
2013年杭電計算機研究生復試---筆試編程
1、簡要描述:輸入一個數,代表要檢測的例子的個數,每個例子中:
輸入兩個時間(格式HH:MM:SS),前面時間減去后面時間,輸出在時鐘上顯示的時間,格式一樣,如果是以為數字的前面補零。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>int main(void) {int n, HH, MM, SS;int hh, mm, ss;scanf("%d", &n);while (n--) {scanf("%d:%d:%d", &HH, &MM, &SS);scanf("%d:%d:%d", &hh, &mm, &ss);if(hh > 12)hh %= 12;if(SS < ss){--MM;SS += 60;}SS -= ss;if(MM < mm){--HH;MM += 60;}MM -= mm;if(HH < hh)HH += 12;HH -= hh;printf("%02d:%02d:%02d\n", HH, MM, SS);}return 0; }
2、簡要描述:一個活動有N(1<N<100)個人參加,一個主持人和N-1個普通參加者,其中所有的人都認識主持人,主持人也認識所有的人,主持人要求N-1個參加者說出他們在參加者中所認識的人數,如果A認識B,則B認識A,所以最少是會認識一個人,就是主持人,他們說出了自己所認識的人數后,需要判斷他們中有沒有人說謊。
輸入:
? ? ? 第一行是N,N=0表示結束
? ? ? 第二行是N-1個數字
輸出:
? ? ? Lie absolutely 或者 Maybe truth?
7?
1 2 4 5 5 3?
9?
3 7 7 7 7 5 6 6?
兩個測試例子中第一個是Lie absolutely,第二個是Maybe truth?
分析:
輸入N個數,再輸入N-1個數
9?
3 7 7 7 7 5 6 6?
先把這N-1個數字按從大到小排序
7 7 7 7 6 6 5 3?
第一個人認識了7個人,除了主持人還剩6個,就當是認識最靠近他后面的6個。
這樣,除去第一個人,后面認識的人就都減少了一個,變成了:
7 6 6 6 5 5 4 3?
再次排序
從第二個人,除了主持人和第一個,應該認識5個人,就當是認識最靠近他后面的5個
這樣,除去這個人,后面認識的人就都減少了一個,變成了
7 6 5 5 4 4 3 3?
排序,相減,重復下去
如果最后出現了0,就說明有人說謊
如果排序后,當前認識的人和其后面的人數都是1了,那一個人都是主持人,也是Maybe truth?
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h> #include <stdlib.h>int cmp(const void *a, const void *b) {return *(int *)b - *(int *)a; }int main(void) {int i, j, n, a[100];while (scanf("%d", &n) != EOF && n) {for(i = 0; i < n - 1; ++i)scanf("%d", &a[i]);for(i = 0; i < n - 1; ++i){qsort(a + i, (n - i - 1), sizeof(int), cmp);if(0 == a[n - 2]){printf("Lie absolutely\n");break;}else if(1 == a[i]){printf("Maybe truth \n");break;}else{for(j = 1; j < a[i]; ++j)--a[i + j];}}}return 0; }
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <iostream> #include <algorithm> using namespace std;int main(void) {int a[3], i;for(i = 0; i < 3; ++i)scanf("%d", &a[i]);sort(a, a + 3); //排序后,直接用兩個最小數的和與第三個數進行比較就可以了if(a[0] + a[1] > a[2])printf("It is a triangle\n");elseprintf("It is not a triangle\n");return 0; }
2、有個人從2003年1月1日開始,三天打魚兩天曬網,請輸入月份、日期,問在當年的某一天他是在打魚還是在曬網。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>int main(void) {int i, m, d, sum;int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};scanf("%d %d", &m, &d);for(i = 1, sum = 0; i < m; ++i)sum += month[i]; sum = sum + d - 1; //計算輸入的某一天距離1月1日的間隔天數if(sum % 5 < 3)printf("打漁\n");elseprintf("曬網\n");return 0; }
3、丑數是這樣定義的:如果一個正整數的素因子只包含 2、3、5、7四種,則它被稱為丑數。以下數列 1, 2, 3,4, 5,6,7,8,9, 10,12,14,15,16,18, 20, 21,24,25, 27.......... 就顯示了前20個丑數。
給出一個正整數N,判斷這個數是否為丑數。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>bool IsUgly(int number) {while(number % 7 == 0) //輸入的整數分別與2、3、5、7進行循環除法運算(在取模運算為0的情況下)number /= 7;while(number % 5 == 0)number /= 5;while(number % 3 == 0)number /= 3;while(number % 2 == 0)number /= 2;return (number == 1) ? true : false; }int main(void) {int n;scanf("%d", &n);if(IsUgly(n))printf("Yes\n");elseprintf("No\n");return 0; }
2012年杭電計算機研究生復試---筆試編程
1、輸入一個十進制的數,把它轉成十六進制。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>int main(void) {int num, i, j;char str[100];i = 0;scanf("%d" , &num);while(num != 0){j = num % 16;if(j < 10)str[i++] = j + '0';elsestr[i++] = j - 10 + 'A';num /= 16;}if(i == 0)printf("0\n");else{for(j = i - 1; j >= 0; --j)printf("%c", str[j]);printf("\n");}return 0; }
2、貪吃蛇,給你一個50X50的表格,貪吃蛇初始化在某個位置,自身長度20格,頭往四個方向移動,每次移動一格,判斷是成功、出界還是撞到自己,具體的題目是用英文描述的,大概意思就是這樣。輸入第一行為移動的步數,第二行為這些步數的方向,輸出判斷。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>#define WORM_LENGTH 20int main(void) {short h[WORM_LENGTH], v[WORM_LENGTH]; // 用于記錄蟲子每一節的位置,(v[0], h[0])是頭部short newHead_v, newHead_h; // 移動一步后頭部的新位置int i, j, steps;int ranIntoItself, ranOffBoard;char moves[1000];scanf("%d", &steps); // 讀入每個測試用例要移動的步數while (steps != 0) {scanf("%s", moves); // 讀入移動方向字符串// 蟲子的初始位置for (i = 0; i < WORM_LENGTH; ++i){h[i] = 30 - i;v[i] = 25;}ranIntoItself = ranOffBoard = 0;for (i = 0; i < steps; ++i){// 計算移動一步后頭部的位置newHead_h = h[0];newHead_v = v[0];switch (moves[i]){case 'E':newHead_h++;break;case 'S':newHead_v++;break;case 'W':newHead_h--;break;case 'N':newHead_v--;break;}// 判斷是否碰到自己的身體for (j = 1; j < WORM_LENGTH - 1; ++j) // 由于移動后尾部位置已前移一格,所以是WORM_LENGTH - 1{if (newHead_h == h[j] && newHead_v == v[j]) {ranIntoItself = 1;break;}}// 判斷是否碰到邊緣if (newHead_h == 0 || newHead_h == 49 || newHead_v == 0 || newHead_v == 49)ranOffBoard = 1;if (ranIntoItself || ranOffBoard)break;// 移動蟲子除頭部后的幾節for (j = WORM_LENGTH - 1; j > 0; --j){h[j] = h[j - 1];v[j] = v[j - 1];}h[0] = newHead_h;v[0] = newHead_v;}// 輸出移動后的狀態if (ranIntoItself)printf("The worm ran into itself on move %d\n", i + 1);else if (ranOffBoard)printf("The worm ran off the board on move %d\n", i + 1);elseprintf("The worm successfully made all %d moves\n", steps);// 繼續讀下一字符串scanf("%d", &steps);}return 0; }
2012杭電復試專業英語筆試翻譯題
請將下面的短文翻譯成中文。
? ? ?Java is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose,concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere"(WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java is currently one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users.
? ? ?The original Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.
參考答案:
? ? ? Java是Sun微系統公司(該公司已并入Oracle公司)的 James Gosling最初開發的一種程序設計語言,在1995年作為Sun公司Java平臺的核心組件發布。這種語言繼承了C和C++的很多語法格式,但具有更簡單的對象模型和更少的低層機制。Java應用程序通常被編譯成字節碼(類文件),可以在任意的Java虛擬機(JVM)上運行而忽視計算機的體系結構。Java是一種通用的、并發的、基于類的和面向對象的語言,特別地設計成具有盡可能低的實現依賴性。該語言的思想是讓應用程序開發者“一次編寫,到處運行”(WORA),這意味著在一個平臺上運行的代碼不需要重新編譯就可以運行在另一個平臺。如今Java已成為在用的最普遍的程序設計語言之一,特別是用于編寫客戶機-服務器的web應用程序,據報道有1000萬的使用者。?
? ? ?最初的Java編譯器、虛擬機和類庫是由Sun公司從1995開始開發的。在2007年5月,遵照Java社區進程(JCP)的要求,Sun在GNU通用公開許可協議(GPL)的規定下重新發布了它的大部分Java技術許可。第三方組織也完成了這些Sun技術的替代實現,比如GNU的Java翻譯器和GNU Classpath等。
?
2013年杭電計算機研究生復試---筆試編程
1、簡要描述:輸入一個數,代表要檢測的例子的個數,每個例子中:
輸入兩個時間(格式HH:MM:SS),前面時間減去后面時間,輸出在時鐘上顯示的時間,格式一樣,如果是以為數字的前面補零。
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h>int main(void) {int n, HH, MM, SS;int hh, mm, ss;scanf("%d", &n);while (n--) {scanf("%d:%d:%d", &HH, &MM, &SS);scanf("%d:%d:%d", &hh, &mm, &ss);if(hh > 12)hh %= 12;if(SS < ss){--MM;SS += 60;}SS -= ss;if(MM < mm){--HH;MM += 60;}MM -= mm;if(HH < hh)HH += 12;HH -= hh;printf("%02d:%02d:%02d\n", HH, MM, SS);}return 0; }
2、簡要描述:一個活動有N(1<N<100)個人參加,一個主持人和N-1個普通參加者,其中所有的人都認識主持人,主持人也認識所有的人,主持人要求N-1個參加者說出他們在參加者中所認識的人數,如果A認識B,則B認識A,所以最少是會認識一個人,就是主持人,他們說出了自己所認識的人數后,需要判斷他們中有沒有人說謊。
輸入:
? ? ? 第一行是N,N=0表示結束
? ? ? 第二行是N-1個數字
輸出:
? ? ? Lie absolutely 或者 Maybe truth?
7?
1 2 4 5 5 3?
9?
3 7 7 7 7 5 6 6?
兩個測試例子中第一個是Lie absolutely,第二個是Maybe truth?
分析:
輸入N個數,再輸入N-1個數
9?
3 7 7 7 7 5 6 6?
先把這N-1個數字按從大到小排序
7 7 7 7 6 6 5 3?
第一個人認識了7個人,除了主持人還剩6個,就當是認識最靠近他后面的6個。
這樣,除去第一個人,后面認識的人就都減少了一個,變成了:
7 6 6 6 5 5 4 3?
再次排序
從第二個人,除了主持人和第一個,應該認識5個人,就當是認識最靠近他后面的5個
這樣,除去這個人,后面認識的人就都減少了一個,變成了
7 6 5 5 4 4 3 3?
排序,相減,重復下去
如果最后出現了0,就說明有人說謊
如果排序后,當前認識的人和其后面的人數都是1了,那一個人都是主持人,也是Maybe truth?
轉載請標明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/6678851 #include <stdio.h> #include <stdlib.h>int cmp(const void *a, const void *b) {return *(int *)b - *(int *)a; }int main(void) {int i, j, n, a[100];while (scanf("%d", &n) != EOF && n) {for(i = 0; i < n - 1; ++i)scanf("%d", &a[i]);for(i = 0; i < n - 1; ++i){qsort(a + i, (n - i - 1), sizeof(int), cmp);if(0 == a[n - 2]){printf("Lie absolutely\n");break;}else if(1 == a[i]){printf("Maybe truth \n");break;}else{for(j = 1; j < a[i]; ++j)--a[i + j];}}}return 0; }
總結
以上是生活随笔為你收集整理的2011---2013年杭电计算机历年研究生复试---笔试编程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2010年杭电计算机研究生复试---笔试
- 下一篇: Main函数中参数argc,argv说明