• <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,最后還有個(gè)空行。
             cout<<S[j].s<<endl;
              //system("PAUSE");
              return   0;
              }
            奇怪的是在vc上能用
            string s ;
            while(cin>>s)
            {};
            在dev c++ 上不行。
            后來才發(fā)現(xiàn)可以
            string s ;
            while(cin>>s)
            {};
            但是不能加 memset(S,0,sizeof(S));
            posted on 2009-07-18 16:11 luis 閱讀(655) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 格式.輸入輸出.數(shù)據(jù)類型
            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久国产综合精品五月天| 伊人色综合久久天天网| 精品少妇人妻av无码久久| 久久久久亚洲AV片无码下载蜜桃 | 精品国产99久久久久久麻豆 | 久久人人爽人人爽AV片| 久久精品亚洲一区二区三区浴池| 精品久久无码中文字幕| 久久亚洲国产成人影院网站| 精品久久久无码21p发布| 日韩亚洲欧美久久久www综合网| 综合久久精品色| 777米奇久久最新地址| 无码人妻久久久一区二区三区| 久久久WWW成人| 久久久久免费看成人影片| 久久影院久久香蕉国产线看观看| 99久久er这里只有精品18| 久久精品国产99久久丝袜| 国产亚洲色婷婷久久99精品| 久久综合色老色| 无码人妻久久一区二区三区蜜桃 | 久久成人国产精品免费软件| 狠狠精品干练久久久无码中文字幕| 精品久久久久久中文字幕人妻最新| 人妻系列无码专区久久五月天| 久久久综合香蕉尹人综合网| 久久免费精品一区二区| 久久人妻少妇嫩草AV无码专区| 久久综合九色综合欧美就去吻| 伊人丁香狠狠色综合久久| 免费国产99久久久香蕉| 久久精品人人做人人爽电影蜜月| 尹人香蕉久久99天天拍| 亚洲国产日韩欧美久久| 久久久久国产精品嫩草影院| 精品国产一区二区三区久久| 国产日韩久久久精品影院首页| 久久精品国产国产精品四凭| 久久se精品一区二区影院| 国产A级毛片久久久精品毛片|