• <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
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊(cè)

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216468
            • 排名 - 117

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            原題: 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提交編譯錯(cuò)誤一次  因?yàn)闃?biāo)準(zhǔn)c++   pow函數(shù)為 pow(double,<type>)第一個(gè)參數(shù)必須為double,但是我再shantou 上用pow(int,int)就過了,都是編譯器惹的禍...
            posted on 2006-02-08 23:40 閱讀(913) 評(píng)論(14)  編輯 收藏 引用 所屬分類: 算法&ACM

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

            怎么判斷輸入結(jié)束
            怎么用簡(jiǎn)單的方法操作字符串,要建立一個(gè)放字符的class嗎?
            我的代碼在機(jī)子上測(cè)試數(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ù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-10 01:12 
            判斷結(jié)束用while(cin>>str) {...} 然后對(duì)每個(gè)str操作行否?

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

            acm用class小題大作拉,還有,線上題目好象不能用文件的
              回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 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();
            }

            這個(gè)怎么也結(jié)束不了  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-10 18:06 
            當(dāng)沒有輸入,就應(yīng)該結(jié)束的  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 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ù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-11 23:39 dzz
            謝謝,我好好看看~  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-11 23:56 dzz
            看懂了,謝謝,你的代碼上如果一個(gè)單詞超出了該行,就換行再輸出單詞,如果想要把它拆開,應(yīng)該如何改呢?

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

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

            其實(shí)用vc 這句好像執(zhí)行不了的,我也不知道,不過估計(jì)linux下的編譯器能:)我是按照邏輯這樣寫,想不到能過:)  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-12 16:04 Dzz
            你那樣結(jié)不結(jié)束都能得到正確答案嘛~  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-12 18:06 
            不能。。。因?yàn)轭}目要求最后 一個(gè)換行符 作為結(jié)束  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-18 18:07 hhh
            真強(qiáng),類存泄漏~~~  回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2006-02-19 01:27 
            是啊,忘記了,不可原諒的錯(cuò)誤!~
              回復(fù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2007-03-07 16:20 阿七
            你的程序好嚇人啊,我是新手,剛才被你的A+B嚇著了。這是我做的simple task,為什么你要編那么多呢,嚴(yán)謹(jǐn)?我沒仔細(xì)看。
            #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ù)  更多評(píng)論
              
            # re: 今天又過條簡(jiǎn)單題,呵呵 2007-03-07 22:10 
            呵呵,因?yàn)槟莻€(gè)時(shí)候我也是新手嘛,不過現(xiàn)在雖然老了,還是一只老菜鳥  回復(fù)  更多評(píng)論
              
            97精品依人久久久大香线蕉97 | 国产精品久久久久影院色| 久久亚洲AV成人无码电影| 久久噜噜电影你懂的| 精品国产乱码久久久久软件| 久久99久久99精品免视看动漫| 国产精品丝袜久久久久久不卡 | 久久99国产精品久久久| 久久国产精品无码网站| 久久久久人妻精品一区二区三区| 热久久国产精品| 亚洲AV成人无码久久精品老人| 66精品综合久久久久久久| 亚洲AV无码1区2区久久| 日本高清无卡码一区二区久久| 国产一区二区三区久久精品| 久久亚洲日韩看片无码| 久久久久国产精品三级网| 久久97精品久久久久久久不卡| 久久久亚洲裙底偷窥综合| 久久se精品一区二区影院 | 亚洲AV成人无码久久精品老人| 久久一本综合| 国产精品99久久久久久www| 东京热TOKYO综合久久精品| 亚洲国产成人久久综合一区77| 精品久久综合1区2区3区激情| 国产精品一久久香蕉国产线看观看 | 99久久精品国产一区二区蜜芽| 久久人妻AV中文字幕| 久久笫一福利免费导航 | 久久国产成人午夜AV影院| 国产精品久久久久久久| 久久男人Av资源网站无码软件| 久久精品中文字幕大胸| 中文字幕无码久久久| 国产精品中文久久久久久久| 久久精品国产亚洲Aⅴ香蕉| 久久精品国产第一区二区| 久久激情亚洲精品无码?V| 久久国产成人午夜aⅴ影院|