收藏 分享(赏)

从网上整理的华为机试题目.doc

上传人:tangtianxu1 文档编号:2843454 上传时间:2018-09-28 格式:DOC 页数:29 大小:559.42KB
下载 相关 举报
从网上整理的华为机试题目.doc_第1页
第1页 / 共29页
从网上整理的华为机试题目.doc_第2页
第2页 / 共29页
从网上整理的华为机试题目.doc_第3页
第3页 / 共29页
从网上整理的华为机试题目.doc_第4页
第4页 / 共29页
从网上整理的华为机试题目.doc_第5页
第5页 / 共29页
点击查看更多>>
资源描述

1、一、华为机试2018 年校招10 号参加的华为的机试,这次的 3 道题难度适中。第一题字符串,第二题贪心算法(会不会?),dp 可以解,第三题长整数相乘。因为题主做过第三题原题,刚开始就把第三题秒了然后开始做第一题,一般 10 分钟就可以搞定。第二题要想一下,不过也差不多是原题,Leetcode 上第 55 题 jump game 应该是此题原型。因为都刷过几乎是原题的原故,一个小时不到 3 题就 AC 完了下面是完整题目和代码题目一、给你一个原始字符串,根据该字符串内每个字符出现的次数,按照 ASCII 码递增顺序重新调整输出。举例!假设原始字符串为eeefgghhh则每种字符出现的次数分别

2、是1.eee 3 次 2.f 1 次 3.gg 1 次 4.hhh 3 次重新排序后输出的字符串如下:efghegheh编写程序,实现上述功能。【温馨提示】1.原始字符串中仅可能出现“数字”和“字母”;2.请注意区分字母大小写。1. #include 2. #include 3. #include 4. #include 5. using namespace std; 6. int main() 7. string str; 8. int a128=0; 9. while (cin str) 10. for(int i=0;i 2. #include 3. #include 4. #inclu

3、de 5. /确定起点后,用一个指针指向最大跳跃点。 6. /搜索最大跳跃点与起点之间能往后走的最远的点,选定该点为起点,其最大跳跃点为终点。重复。 7. #define MAX 1000 8. using namespace std; /每次跳的最大长度为 ai+i。 9. if(ai + i stepMax) /搜索最大的跳跃点,记为 index 10. stepMax = ai +i; 11. index =i; 12. 13. if(i = end) /搜索完毕,从 index(能跳最远的位置)开始继续跳 14. end = stepMax; 15. +count; 16. i = i

4、ndex; 17. 18. 19. return count; 20. 21. 22. int main() 23. 24. int n; 25. while (cin n) 26. int aMAX=0; 27. for(int i=0;i ai; 29. 30. cout 2. using namespace std; 3. 4. 5. 6. int multiply (string ma,string mb,string 10. string chengshuB = mb; 11. unsigned long a = chengshuA.length(); 12. unsigned lo

5、ng b = chengshuB.length(); 13. int strRst_length = 0; 14. unsigned long c = (a+1)*(b+1); 15. int *p = new intc; 16. int *pA = new inta; 17. int *pB = new intb; 18. 19. 20. if (a = 0) | (b = 0) 21. return -1; 22. 23. for (int i = 0; i != c; i+) 24. pi = 0; 25. 26. 27. for (string:size_type index = 0;

6、 index != chengshuA.length(); index+) 28. pAa-1-index = chengshuA.at(index) - 0; 29. 30. 31. for (string:size_type index = 0; index != chengshuB.length(); index+) 32. pBb-1-index = chengshuB.at(index) - 0; 33. 34. 35. for (int temp_b = 0; temp_b != b; temp_b+) 36. 37. for (int temp_a = 0; temp_a !=

7、a; temp_a+) 38. 39. 40. int temp = ptemp_a+temp_b + pAtemp_a*pBtemp_b; 41. ptemp_a+temp_b = temp % 10; 42. int carry = temp/10; 43. 44. int x = temp_a + temp_b +1; 45. 46. while(carry != 0) 47. 48. px = px + carry%10; 49. carry = carry/10; 50. x+; 51. 52. 53. 54. 55. while (c- 0) 56. 57. if (pc != 0

8、) 58. 59. strRst_length = c + 1; 60. break; 61. 62. 63. 64. char ch; 65. for (int i = strRst_length - 1; i = 0 ; i-) 66. 67. ch = pi + 0; 68. strRst.push_back(ch); 69. 70. if (strRst.empty() 71. 72. strRst = “0“; 73. 74. 75. return 0; 76. 77. 78. int main(void) 79. 80. string a ; 81. string b ; 82.

9、while (cin ab) 83. string strRst = “0“; 84. multiply (a,b,strRst); 85. cout 0;i+) ai=x%2; x/=2; for(i-;i=0;i-) /for test printf(“%d“,ai); cout #include #include using namespace std; int num400400; int len400400; int max(int a,int b) if(ab) return a; else return b; int main() int m,n; scanf(“%d %d“,

10、for(int i=1;i S; int ans=0,tmp; for(int j=n;j0;j-) int W,L; tmp=0; if(ans=j*m) break; S.push(0); for(int i=1;ilenS.top()j) S.push(i); else while(!S.empty() int main() int m,n; int i,j; int temp; bool flag; cinmn; for(i=m;i=2 就是结果输出。那么接下来问题来了:1.计算机如何接受这些输入,因为有要求以“, ”为分隔符因为有“, ”,作为字符存在,又不限制输入的具体个数,所以无

11、法用 int 数组接收这些输入,此处应选择 C+字符串 string str;作为接收输入。那么很明显,本题对 C+字符串是一个考察点,并且考察重要程度甚至大于这道题的算法本身。2.如何在一个 str 中取得这些数字毫无疑问考察应试者的字符串处理能力。我先想的是以逗号为分隔符,由于 C+字符串可以以下标取出值(如 stri), 取得每一个逗号的位置,后一个减前一个得到中间的数字。然后发现 str.substr()函数会连逗号一起取出,所以这不是一个可取的方法,更不是一个好方法。好的处理方法应该是这样,如下:char a10; int p=0; int numN; int i,j,cnt=0;

12、cpp view plain copycinstr; for(i=0;iusing namespace std;void main(void)char table33 = 2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z;unsigned int a,b,c;int i,j;cina;cinb;cinc;unsigned int tmp1,tmp2;tmp1 = (a resi = tmp;tmp = 0x00;for(i=0;i5);fina15 = tabletmp;for(i=0;i#include #incl

13、ude #include #include using namespace std;int getNum(string inpus)int objNum = 0,t = 1;for (long i = inpus.length() - 1; i = 0 ; - i) if (isdigit(inpusi) t *= 10; else break;return objNum;int main(int argc, const char * argv) string inpus;cin inpus;vector objStringInfo;string a = “;for (int i = 0; i

14、 #include #include using namespace std;int getStringNum(string inpus)int objNum = 0,t = 1;for (long i = inpus.length() - 1; i = 0 ; - i) if (isdigit(inpusi) t *= 10; else break;return objNum;vector getNum(string inputs)vector v;vector num;string buff = “;for (int i = 0;i s;vector array = getNum(s);i

15、nt k = 0,result100 = 0;for (int i = 0;i #include #include using namespace std;string subtraction(string a,string b)/大数减法int arr1100 = 0,arr2100 = 0,arr3100 = 0;for (long i = a.length() - 1,k = 0;i = 0; -i) arr1k+ = ai - 0;for (long i = b.length() - 1,k = 0;i = 0; -i) arr2k+ = bi - 0;long len = (a.le

16、ngth() b.length() ? a.length():b.length();int k = 0;for (int i = 0;i = 0; -i) buff = arr3i + 0;result += buff;return result;string aModeB(string a,string b)/大数取模if (a.length() b.length() while (pare(b) 0) a = subtraction(a, b);return a;else if (a.length() = b.length()if(pare(b) 0)while (pare(b) 0) a = subtraction(a, b);return a;elsereturn a;elsereturn a;int main(int argc, const char * argv) string a,b;cin a;cin b;cout aModeB(a, b) endl;return 0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 专业基础教材

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报