2015届华为校园招聘机试题
生活随笔
收集整理的這篇文章主要介紹了
2015届华为校园招聘机试题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
第一題(60分):
? ? ? ?按要求分解字符串,輸入兩個(gè)數(shù)M,N;M代表輸入的M串字符串,N代表輸出的每串字符串的位數(shù),不夠補(bǔ)0。例如:輸入2,8, “abc” ,“123456789”,則輸出為“abc00000”,“12345678“,”90000000”
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> using namespace std;void solve(char *str , int n , int len) {int i , j , k , quotient , remainder;quotient = len / n; //原字符串被分解的個(gè)數(shù)remainder = len - n * quotient; //剩余的字符串的個(gè)數(shù)for(i = 0 ; i < len ; i += n){if(len - i < n){k = n - len + i;for(j = i ; j < len ; ++j)printf("%c" , str[j]);for(j = 0 ; j < k ; ++j)putchar('0');}else{for(j = i ; j < i + n ; ++j)printf("%c" , str[j]);}putchar(' ');}printf("\n"); }int main(void) {int i , m , n , len;char str[1000];while(scanf("%d %d", &m , &n) != EOF){for(i = 0 ; i < m ; ++i){scanf("%s" , str);len = strlen(str);solve(str , n , len);}}return 0; } 第一題:拼音轉(zhuǎn)數(shù)字
輸入是一個(gè)只包含拼音的字符串,請輸出對應(yīng)的數(shù)字序列。轉(zhuǎn)換關(guān)系如下:
描述: ? ? ?拼音 ? ? ? ?yi ?er ?san ?si ?wu ?liu ?qi ?ba ?jiu
? ? ? 阿拉伯?dāng)?shù)字 ? ? ? ?1 ? 2 ? 3 ? ? ?4 ? 5 ? ?6 ? ?7 ? 8 ? 9
輸入字符只包含小寫字母,所有字符都可以正好匹配
運(yùn)行時(shí)間限制:無限制
內(nèi)存限制: ? ? ? 無限制
輸入: ? ? ? ? ? ? ?一行字符串,長度小于1000
輸出: ? ? ? ? ? ? ?一行字符(數(shù)字)串
樣例輸入: ? ? ? yiersansi
樣例輸出: ? ? ? 1234
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> using namespace std;void solve(char *str , int len) {int i;for(i = 0 ; i < len ; ){switch(str[i]){case 'y':putchar('1');i += 2;break;case 'e':putchar('2');i += 2;break;case 's':if(str[i + 1] == 'a'){putchar('3');i += 3;}else{putchar('4');i += 2;}break;case 'w':putchar('5');i += 2;break;case 'l':putchar('6');i += 3;break;case 'q':putchar('7');i += 2;break;case 'b':putchar('8');i += 2;break;case 'j':putchar('9');i += 3;break;}}printf("\n"); }int main(void) {int len;char str[1000];while(scanf("%s" , str) != EOF){len = strlen(str);solve(str , len);}return 0; } 第二題:去除重復(fù)字符并排序
運(yùn)行時(shí)間限制:無限制
內(nèi)容限制: ? ? ? 無限制
輸入: ? ? ? ? ? ? ?字符串
輸出: ? ? ? ? ? ? ?去除重復(fù)字符并排序的字符串
樣例輸入: ? ? ? aabcdefff
樣例輸出: ? ? ? abcdef
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> #include<memory> using namespace std;void solve(char *str , int len) {int i , hash[256];memset(hash , 0 , sizeof(hash));for(i = 0 ; i < len ; ++i){if(0 == hash[str[i]])hash[str[i]] = 1;}for(i = 0 ; i < 256 ; ++i){if(0 != hash[i])putchar(i);}printf("\n"); }int main(void) {int len;char str[1000];while(scanf("%s" , str) != EOF){len = strlen(str);solve(str , len);}return 0; } 第三題:等式變換
輸入一個(gè)正整數(shù)X,在下面的等式左邊的數(shù)字之間添加+號(hào)或者-號(hào),使得等式成立。
1 2 3 4 5 6 7 8 9 = X
比如:
12-34+5-67+89 = 5
1+23+4-5+6-7-8-9 = 5
請編寫程序,統(tǒng)計(jì)滿足輸入整數(shù)的所有整數(shù)個(gè)數(shù)。
輸入: ? ? ? 正整數(shù),等式右邊的數(shù)字
輸出: ? ? ? 使該等式成立的個(gè)數(shù)
樣例輸入:5
樣例輸出:21
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> using namespace std;int ops[21]; const char sym[3] = {'+' , '-' , ' '}; int result , num;void dfs(int layer, int currentResult, int lastOp, int lastSum) {lastSum *= (layer > 9) ? 100 : 10;lastSum += layer;if(layer == 9){currentResult += (lastOp) ? (-1 * lastSum) : lastSum;if(currentResult == result){++num;printf("1");for(int i = 2 ; i <= 9 ; ++i){if(sym[ops[i-1]] != ' ')printf(" %c ", sym[ops[i-1]]);printf("%d", i);}printf(" = %d\n" , result);}return;}ops[layer] = 2;dfs(layer + 1 , currentResult , lastOp , lastSum); //ContinuecurrentResult += (lastOp)? (-1 * lastSum) : lastSum;ops[layer] = 0;dfs(layer + 1 , currentResult , 0 , 0); //Plusops[layer] = 1;dfs(layer + 1 , currentResult , 1 , 0); //Minus }int main(void) {while(scanf("%d", &result) != EOF){num = 0;dfs(1 , 0 , 0 , 0);printf("%d\n" , num);}return 0; }
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767
與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖
? ? ? ?按要求分解字符串,輸入兩個(gè)數(shù)M,N;M代表輸入的M串字符串,N代表輸出的每串字符串的位數(shù),不夠補(bǔ)0。例如:輸入2,8, “abc” ,“123456789”,則輸出為“abc00000”,“12345678“,”90000000”
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> using namespace std;void solve(char *str , int n , int len) {int i , j , k , quotient , remainder;quotient = len / n; //原字符串被分解的個(gè)數(shù)remainder = len - n * quotient; //剩余的字符串的個(gè)數(shù)for(i = 0 ; i < len ; i += n){if(len - i < n){k = n - len + i;for(j = i ; j < len ; ++j)printf("%c" , str[j]);for(j = 0 ; j < k ; ++j)putchar('0');}else{for(j = i ; j < i + n ; ++j)printf("%c" , str[j]);}putchar(' ');}printf("\n"); }int main(void) {int i , m , n , len;char str[1000];while(scanf("%d %d", &m , &n) != EOF){for(i = 0 ; i < m ; ++i){scanf("%s" , str);len = strlen(str);solve(str , n , len);}}return 0; } 第一題:拼音轉(zhuǎn)數(shù)字
輸入是一個(gè)只包含拼音的字符串,請輸出對應(yīng)的數(shù)字序列。轉(zhuǎn)換關(guān)系如下:
描述: ? ? ?拼音 ? ? ? ?yi ?er ?san ?si ?wu ?liu ?qi ?ba ?jiu
? ? ? 阿拉伯?dāng)?shù)字 ? ? ? ?1 ? 2 ? 3 ? ? ?4 ? 5 ? ?6 ? ?7 ? 8 ? 9
輸入字符只包含小寫字母,所有字符都可以正好匹配
運(yùn)行時(shí)間限制:無限制
內(nèi)存限制: ? ? ? 無限制
輸入: ? ? ? ? ? ? ?一行字符串,長度小于1000
輸出: ? ? ? ? ? ? ?一行字符(數(shù)字)串
樣例輸入: ? ? ? yiersansi
樣例輸出: ? ? ? 1234
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> using namespace std;void solve(char *str , int len) {int i;for(i = 0 ; i < len ; ){switch(str[i]){case 'y':putchar('1');i += 2;break;case 'e':putchar('2');i += 2;break;case 's':if(str[i + 1] == 'a'){putchar('3');i += 3;}else{putchar('4');i += 2;}break;case 'w':putchar('5');i += 2;break;case 'l':putchar('6');i += 3;break;case 'q':putchar('7');i += 2;break;case 'b':putchar('8');i += 2;break;case 'j':putchar('9');i += 3;break;}}printf("\n"); }int main(void) {int len;char str[1000];while(scanf("%s" , str) != EOF){len = strlen(str);solve(str , len);}return 0; } 第二題:去除重復(fù)字符并排序
運(yùn)行時(shí)間限制:無限制
內(nèi)容限制: ? ? ? 無限制
輸入: ? ? ? ? ? ? ?字符串
輸出: ? ? ? ? ? ? ?去除重復(fù)字符并排序的字符串
樣例輸入: ? ? ? aabcdefff
樣例輸出: ? ? ? abcdef
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> #include<memory> using namespace std;void solve(char *str , int len) {int i , hash[256];memset(hash , 0 , sizeof(hash));for(i = 0 ; i < len ; ++i){if(0 == hash[str[i]])hash[str[i]] = 1;}for(i = 0 ; i < 256 ; ++i){if(0 != hash[i])putchar(i);}printf("\n"); }int main(void) {int len;char str[1000];while(scanf("%s" , str) != EOF){len = strlen(str);solve(str , len);}return 0; } 第三題:等式變換
輸入一個(gè)正整數(shù)X,在下面的等式左邊的數(shù)字之間添加+號(hào)或者-號(hào),使得等式成立。
1 2 3 4 5 6 7 8 9 = X
比如:
12-34+5-67+89 = 5
1+23+4-5+6-7-8-9 = 5
請編寫程序,統(tǒng)計(jì)滿足輸入整數(shù)的所有整數(shù)個(gè)數(shù)。
輸入: ? ? ? 正整數(shù),等式右邊的數(shù)字
輸出: ? ? ? 使該等式成立的個(gè)數(shù)
樣例輸入:5
樣例輸出:21
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767 #include<iostream> #include<cstdio> using namespace std;int ops[21]; const char sym[3] = {'+' , '-' , ' '}; int result , num;void dfs(int layer, int currentResult, int lastOp, int lastSum) {lastSum *= (layer > 9) ? 100 : 10;lastSum += layer;if(layer == 9){currentResult += (lastOp) ? (-1 * lastSum) : lastSum;if(currentResult == result){++num;printf("1");for(int i = 2 ; i <= 9 ; ++i){if(sym[ops[i-1]] != ' ')printf(" %c ", sym[ops[i-1]]);printf("%d", i);}printf(" = %d\n" , result);}return;}ops[layer] = 2;dfs(layer + 1 , currentResult , lastOp , lastSum); //ContinuecurrentResult += (lastOp)? (-1 * lastSum) : lastSum;ops[layer] = 0;dfs(layer + 1 , currentResult , 0 , 0); //Plusops[layer] = 1;dfs(layer + 1 , currentResult , 1 , 0); //Minus }int main(void) {while(scanf("%d", &result) != EOF){num = 0;dfs(1 , 0 , 0 , 0);printf("%d\n" , num);}return 0; }
轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/hackbuteer1/article/details/39253767
與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖
總結(jié)
以上是生活随笔為你收集整理的2015届华为校园招聘机试题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里巴巴集团2014秋季校园招聘笔试题
- 下一篇: 【强烈推荐】程序猿们,九度Online