多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > 2014微軟實習生在線編程試題1

2014微軟實習生在線編程試題1

來源:程序員人生   發布時間:2014-08-30 16:40:39 閱讀次數:4647次

2014微軟實習生在線編程試題1,大家一起來看看微軟有什么題目吧
1,Description

For this question, your program is required to process an input string containing only ASCII characters between ‘0’ and ‘9’, or between ‘a’ and ‘z’ (including ‘0’, ‘9’, ‘a’, ‘z’).

Your program should reorder and split all input string characters into multiple segments, and output all segments as one concatenated string. The following requirements should also be met,
1. Characters in each segment should be in strictly increasing order. For ordering, ‘9’ is larger than ‘0’, ‘a’ is larger than ‘9’, and ‘z’ is larger than ‘a’ (basically following ASCII character order).
2. Characters in the second segment must be the same as or a subset of the first segment; and every following segment must be the same as or a subset of its previous segment.

Your program should output string “<invalid input string>” when the input contains any invalid characters (i.e., outside the '0'-'9' and 'a'-'z' range).

Input

Input consists of multiple cases, one case per line. Each case is one string consisting of ASCII characters.

Output

For each case, print exactly one line with the reordered string based on the criteria above.

樣例輸入
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee
樣例輸出
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa
該問題主要采用哈希比較簡單,我就不做介紹了直接上代碼:下面代碼提交時TLE,實際上可以優化例如設置temp1[255]存儲hash值是沒必要這么大。
  1. 01.#include<stdio.h>    
  2. 02.#include<stdlib.h>    
  3. 03.#include<string.h>    
  4. 04.char temp[10][100];   
  5. 05.   
  6. 06.void process(char *String)   
  7. 07.{   
  8. 08.    int temp1[256] = {0};   
  9. 09.   
  10. 10.    int index = 0;   
  11. 11.       
  12. 12.    if(String==NULL)   
  13. 13.        return ;   
  14. 14.       
  15. 15.    int len = strlen(String);   
  16. 16.    int i;   
  17. 17.    for(i = 0; i < len; i++)   
  18. 18.    {   
  19. 19.        if((String[i] >='0' && String[i] <='9') || (String[i] >= 'a' && String[i] <='z') )   
  20. 20.        {   
  21. 21.            index = String[i] - '0';   
  22. 22.            temp1[index]++;   
  23. 23.        }   
  24. 24.        else   
  25. 25.        {   
  26. 26.            printf("<invalid input string>");   
  27. 27.        }   
  28. 28.    }   
  29. 29.       
  30. 30.    index = 0;   
  31. 31.       
  32. 32.    while(1)   
  33. 33.    {   
  34. 34.        for(i = 0; i < 256; i++)   
  35. 35.        {   
  36. 36.               
  37. 37.            if(temp1[i] !=0)   
  38. 38.            {   
  39. 39.                String[index] = i + '0';   
  40. 40.                index++;   
  41. 41.                temp1[i]--;   
  42. 42.            }   
  43. 43.               
  44. 44.        }   
  45. 45.           
  46. 46.        if(index == len)   
  47. 47.        {   
  48. 48.            printf("%s\n", String);   
  49. 49.            return;   
  50. 50.        }   
  51. 51.    }   
  52. 52.}   
  53. 53.   
  54. 54.int main()   
  55. 55.{   
  56. 56.    int i = 0;   
  57. 57.    while(gets(temp[i++]) != NULL);   
  58. 58.    i--;   
  59. 59.    int j;   
  60. 60.    for(j = 0; j<i; j++)   
  61. 61.    {   
  62. 62.        process(temp[j]);   
  63. 63.    }   
  64. 64.    return 0;   
  65. 65.}   
  66. 66.       

 

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲精品高清视频 | 欧美成成人免费 | 免费一级欧美片在线观免看 | 国产日韩一区二区三区在线观看 | 亚洲国产欧美在线不卡中文 | 国产91一区二区在线播放不卡 | 男女激情免费视频 | 欧美大片天天免费看视频 | 抖音毛片 | 福利精品 | 欧美一级视频高清片 | 波多野结衣一区二区 | 香蕉在线视频网站 | 国产极品美女在线 | 伊人精品影院一本到欧美 | 麻豆免费版在线观看 | www.九色.com| 依人在线免费视频 | 欧美日一区| 久久婷五月天 | 在线观看www. | 亚洲福利国产 | 一区二区成人国产精品 | 亚洲综合视频网 | 男女激情视频网站 | 亚洲国产成人精品女人久久久 | 午夜久久久 | 国产综合精品一区二区 | 久久精品视频一区 | 在线一区二区三区 | 久久国产精品成人免费 | 人人澡人人擦人人免费 | 色欧美亚洲 | 伊人伊人| 日一区二区三区 | 亚洲国产成人精品青青草原100 | 成人午夜又粗又硬有大 | 性做久久久久久久 | 亚洲精品一区二区三区在线观看 | 免费看亚洲| 国产日韩精品视频一区二区三区 |