• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 195,  comments - 30,  trackbacks - 0
            2152: A Special Sorting
            Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
            stdin/stdout 3s 8192K 356 152 Standard

            Give you a sequence of words, can you sort them in dictionary order?

            eg.

            yes
            accidental
            baby
            accept
            accident
            
            In dictionary order, those words should be printed as the following
            accept
            accident
            accidental
            baby
            yes
            
            But we will make an interesting rule this time. See your keyboard or the picture below:

            there are ONLY 26 letters in lower-case we will use, and we assume that the letter above is bigger than the letter below, and the left is bigger than the right. For example, 'q' is bigger than 'a', 'c' is bigger than 'v'. So the example at the beginning whill be...

            Input and Output

            the input will only contain a sequence of words which is less than 1500. the output should print the sorted words each in a single line.

            Sample Input

            yes
            accidental
            baby
            accept
            accident
            

            Sample Output

            baby
            accident
            accidental
            accept
            yes
            

            水題啊!
            #include<iostream>
            #include<cstdlib>
            #include<string>
            #include<algorithm>
            using namespace std;
            int Map[27];
            struct M{
             char s[30];
            }S[1500];
            char table[26]={'q','w','e','r','t','y','u','i','o','p','a','s','d',
            'f','g','h','j','k','l','z','x','c','v','b','n','m'};
            bool operator<(M a,M b)
            {
             int i=strlen(a.s);
             int j=strlen(b.s);
             if(i<j)
             j=i;
             for(int k=0;k<j;k++)
             {
              if(Map[(a.s[k])-'a']<Map[(b.s)[k]-'a'])
              return false;
              if(Map[(a.s[k])-'a']>Map[(b.s)[k]-'a'])
              return true;
             }
             return i==j;//Èç¹ûabcd,abc,abcd<abc
            }
            void search(char key)
            {
             int i;
            for(i=0;i<26;i++)
            {
             if(key==table[i])
             {
              Map[key-'a']=i;
              break;
             }
            }
            }
              int main()
              {
              freopen("s.txt","r",stdin);  
              freopen("key.txt","w",stdout);
              int i;
              string t;
              memset(S,0,sizeof(S));
              for(i=0;i<26;i++)
              {
              search('a'+i);
              }
              i=0;
              while(!cin.eof())
               { 
             cin.getline(S[i++].s,30);//不能用cin>>s;否則runtime  error
               }
             sort(S,S+i-1);
             for(int j=0;j<i-1;j++)//必須用i-1,最后還有個空行。
             cout<<S[j].s<<endl;
              //system("PAUSE");
              return   0;
              }
            奇怪的是在vc上能用
            string s ;
            while(cin>>s)
            {};
            在dev c++ 上不行。
            后來才發現可以
            string s ;
            while(cin>>s)
            {};
            但是不能加 memset(S,0,sizeof(S));
            posted on 2009-07-18 16:11 luis 閱讀(658) 評論(0)  編輯 收藏 引用 所屬分類: 格式.輸入輸出.數據類型
            <2012年2月>
            2930311234
            567891011
            12131415161718
            19202122232425
            26272829123
            45678910

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            精品无码久久久久久久动漫| 亚洲欧美日韩久久精品第一区| 久久无码人妻一区二区三区 | 精品国际久久久久999波多野| 久久亚洲sm情趣捆绑调教| 亚洲综合久久夜AV | 久久伊人五月丁香狠狠色| 中文国产成人精品久久亚洲精品AⅤ无码精品| 99久久精品国产一区二区| 91精品国产高清久久久久久国产嫩草 | 免费精品99久久国产综合精品| 99久久精品国产高清一区二区| 久久er99热精品一区二区| 久久婷婷国产麻豆91天堂| 久久精品成人国产午夜| 丁香久久婷婷国产午夜视频| 人妻系列无码专区久久五月天| 亚洲精品无码久久久| 久久这里只有精品18| 99麻豆久久久国产精品免费| 国产成人久久精品麻豆一区| 久久毛片免费看一区二区三区| 伊人久久成人成综合网222| 精品无码久久久久国产| 日本道色综合久久影院| 久久久久久久久66精品片| 久久福利青草精品资源站免费| 人人狠狠综合久久亚洲高清| 久久99精品国产麻豆宅宅| 色综合久久久久| 日产久久强奸免费的看| 91精品国产综合久久精品| 亚洲人成无码久久电影网站| 久久精品国产亚洲麻豆| 99久久做夜夜爱天天做精品| 久久综合丁香激情久久| 99精品国产99久久久久久97| 国产精品美女久久久网AV| 欧美黑人激情性久久| 久久综合伊人77777麻豆| 久久r热这里有精品视频|