• <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>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2007年11月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216403
            • 排名 - 117

            最新評論

            閱讀排行榜

            評論排行榜

            原題: A Simple Task
            Given a positive integer n and the odd integer o and the nonnegative
            integer p such that n = o2^p.


            Example

            For n = 24, o = 3 and p = 3.


            Task

            Write a program which for each data set:

            reads a positive integer n,

            computes the odd integer o and the nonnegative integer p such that n = o2^p,

            writes the result.


            Input

            The first line of the input contains exactly one positive integer d
            equal to the number of data sets, 1 <= d <= 10. The data sets follow.

            Each data set consists of exactly one line containing exactly one
            integer n, 1 <= n <= 10^6.


            Output


            Line i, 1 <= i <= d, corresponds to the i-th input and should contain two
            integers o and p separated by a single space such that n = o2^p.


            Sample Input

            1
            24


            Sample Output

            3 3

             
            #include<iostream>
            #include
            <cmath>
            using namespace std;

            int main()
            {
                
            int set_num;
                
            int *set = NULL;
                
            int i,j,k;
                
            int temp;
                
            bool flag;
                cin
            >>set_num;
                
            set = new int[set_num];
                
            for (i = 0;i<set_num;i++)
                    cin
            >>set[i];

                
            for (i = 0;i<set_num;i++)
                
            {
                    
            if (set[i]%2!=0)
                    
            {
                        cout
            <<set[i]<<' '<<0<<endl;
                        
            continue;
                    }

                    flag 
            = false;
                    
            for (j = 1;j<=set[i]/2;j+=2)
                    
            {
                        temp 
            = 0;
                        k
            =1;
                        
            while(temp<set[i])
                        
            {
                            temp 
            = j*pow(2,k);
                            
            if (temp==set[i])
                            
            {
                                cout
            <<j<<' '<<k<<endl;
                                flag 
            = true;
                                
            break;               
                            }

                            
            else
                                k
            ++;
                        }

                        
            if (flag)
                            
            break;
                    }

                }



                
            return 0;
            }


            上面是我提交的程序
            在zju提交編譯錯誤一次  因為標準c++   pow函數(shù)為 pow(double,<type>)第一個參數(shù)必須為double,但是我再shantou 上用pow(int,int)就過了,都是編譯器惹的禍...
            posted on 2006-02-08 23:40 閱讀(912) 評論(14)  編輯 收藏 引用 所屬分類: 算法&ACM

            FeedBack:
            # re: 今天又過條簡單題,呵呵 2006-02-09 19:09 dzz
            幫我看看
            http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=2271

            怎么判斷輸入結(jié)束
            怎么用簡單的方法操作字符串,要建立一個放字符的class嗎?
            我的代碼在機子上測試數(shù)據(jù)都沒完全通過
            #define SZ 80

            #include <iostream>
            #include <string>
            #include <strstream>
            #include <fstream>
            using namespace std;
            char buf[SZ];
            char* p;
            int dis=0;

            main(){
            ostrstream cl;
            string st;
            ofstream s("temp.txt");
            char a;
            while(getline(cin,st,'\n')){
            s<<st;
            a=getchar();
            if (a=='\n') break;
            else s<<a;

            };
            s<<ends;
            s.close();

            ifstream o("temp.txt");
            while(o.get(buf,SZ)){
            if (strstr(buf,"<br>")) {
            dis = (strstr(buf,"<br>") - buf);
            o.seekg(dis-80+6,ios::cur);
            for (int ctr=0;ctr<dis;ctr++) cl<<buf[ctr];
            cl<<endl;
            }
            else if(strstr(buf,"<hr>")){
            dis = (strstr(buf,"<hr>") - buf);
            o.seekg(dis-80+6,ios::cur);
            for (int ctr=0;ctr<dis;ctr++) cl<<buf[ctr];cl<<endl; for (int ctr=0;ctr<80;ctr++) cl<<'-';

            }
            else if(strstr(buf," ")){

            }
            else cl<<buf<<endl;
            }

            cout<<cl.rdbuf()<<endl;


            }  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-10 01:12 
            判斷結(jié)束用while(cin>>str) {...} 然后對每個str操作行否?

            題目只有<br> <hr> 和80字換行,對這三種規(guī)則分別操作,就應(yīng)該可以了

            acm用class小題大作拉,還有,線上題目好象不能用文件的
              回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-10 13:59 Dzz
            #include <strstrea.h>
            #include <iostream.h>

            main(){
            char str[80];
            ostrstream os;
            while (cin>>str) {os<<str;}
            cout << os.rdbuf();
            }

            這個怎么也結(jié)束不了  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-10 18:06 
            當沒有輸入,就應(yīng)該結(jié)束的  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-11 19:28 
            我在zju上過了

            #include<iostream>
            #include<string>
            using namespace std;

            int main()
            {
            const char br = '\n' ;
            char hr[82];
            char str[81];
            int lineCharNum = 0;
            int charLength = 0;
            int i;
            bool flag;
            for (i=0;i<80;i++)
            hr[i] = '-';
            hr[i] = '\n';
            hr[i+1] = '\0';

            while (cin>>str)
            {
            flag = true;
            if(strcmp(str,"<br>")==0)
            {
            cout<<br;
            lineCharNum = 0;
            flag = false;
            continue;
            }
            if(strcmp(str,"<hr>")==0)
            if(lineCharNum==0)
            {
            cout<<hr;
            flag = false;
            continue;
            }
            else
            {
            cout<<br<<hr;
            flag = false;
            lineCharNum = 0;
            continue;
            }
            charLength = strlen(str);

            if (lineCharNum==0)
            {
            cout<<str;
            lineCharNum = charLength;
            }
            else if (charLength+lineCharNum+1<=80)
            {
            cout<<' '<<str;
            lineCharNum += charLength+1;
            }
            else
            {
            cout<<br<<str;
            lineCharNum = charLength;
            }
            }
            if (flag) cout<<endl;
            return 0;
            }  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-11 23:39 dzz
            謝謝,我好好看看~  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-11 23:56 dzz
            看懂了,謝謝,你的代碼上如果一個單詞超出了該行,就換行再輸出單詞,如果想要把它拆開,應(yīng)該如何改呢?

            還有就是
            if (flag) cout<<endl;
            return 0;

            這兩個語句不知道什么情況程序可以運行到這里??
            我們交換一下blog鏈接吧,我已經(jīng)添加你了~
            我的Http://www.dzzsoft.net/blog2/  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-12 14:26 
            if (flag) cout<<endl;
            return 0;

            其實用vc 這句好像執(zhí)行不了的,我也不知道,不過估計linux下的編譯器能:)我是按照邏輯這樣寫,想不到能過:)  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-12 16:04 Dzz
            你那樣結(jié)不結(jié)束都能得到正確答案嘛~  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-12 18:06 
            不能。。。因為題目要求最后 一個換行符 作為結(jié)束  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-18 18:07 hhh
            真強,類存泄漏~~~  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-19 01:27 
            是啊,忘記了,不可原諒的錯誤!~
              回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2007-03-07 16:20 阿七
            你的程序好嚇人啊,我是新手,剛才被你的A+B嚇著了。這是我做的simple task,為什么你要編那么多呢,嚴謹?我沒仔細看。
            #include <iostream>
            using namespace std;

            int main()
            {
            int n,o,p=0;
            cin >> n;
            o = n;
            while(o % 2 == 0)
            {
            o = o / 2;
            p++;
            }
            cout << n <<"=" << o << "*" << "2^" << p << endl;
            return 0;
            }  回復(fù)  更多評論
              
            # re: 今天又過條簡單題,呵呵 2007-03-07 22:10 
            呵呵,因為那個時候我也是新手嘛,不過現(xiàn)在雖然老了,還是一只老菜鳥  回復(fù)  更多評論
              
            亚洲精品成人久久久| 久久亚洲AV无码精品色午夜 | 久久精品9988| 久久久久久免费视频| 久久这里有精品| 国产欧美久久久精品影院| 亚洲精品无码久久久| 综合久久一区二区三区 | 久久久久久久女国产乱让韩| 色天使久久综合网天天| 中文字幕精品无码久久久久久3D日动漫| 久久激情亚洲精品无码?V| 久久久久亚洲AV成人网| 亚洲欧美日韩久久精品| 99久久国产宗和精品1上映| 色欲av伊人久久大香线蕉影院 | 精品久久久久久无码专区| 国产∨亚洲V天堂无码久久久| 久久青草国产精品一区| 久久久久人妻一区精品果冻| 麻豆精品久久久久久久99蜜桃| 少妇高潮惨叫久久久久久| 久久国产精品-国产精品| 欧美色综合久久久久久| 久久A级毛片免费观看| 品成人欧美大片久久国产欧美...| 亚洲精品无码久久不卡| 久久国产色AV免费看| 国产毛片久久久久久国产毛片| 欧美日韩精品久久久久| 99久久精品国产免看国产一区| 久久精品成人免费国产片小草| 久久精品国产免费观看| 99久久精品无码一区二区毛片| 久久99这里只有精品国产| 99久久免费国产精品热| 久久午夜福利无码1000合集| 色成年激情久久综合| 久久青青草原亚洲av无码app| 久久涩综合| 亚洲国产成人久久综合一|