• <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)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216452
            • 排名 - 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函數為 pow(double,<type>)第一個參數必須為double,但是我再shantou 上用pow(int,int)就過了,都是編譯器惹的禍...
            posted on 2006-02-08 23:40 閱讀(913) 評論(14)  編輯 收藏 引用 所屬分類: 算法&ACM

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

            怎么判斷輸入結束
            怎么用簡單的方法操作字符串,要建立一個放字符的class嗎?
            我的代碼在機子上測試數據都沒完全通過
            #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;


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

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

            acm用class小題大作拉,還有,線上題目好象不能用文件的
              回復  更多評論
              
            # 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();
            }

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

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

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

            其實用vc 這句好像執行不了的,我也不知道,不過估計linux下的編譯器能:)我是按照邏輯這樣寫,想不到能過:)  回復  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-12 16:04 Dzz
            你那樣結不結束都能得到正確答案嘛~  回復  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-12 18:06 
            不能。。。因為題目要求最后 一個換行符 作為結束  回復  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-18 18:07 hhh
            真強,類存泄漏~~~  回復  更多評論
              
            # re: 今天又過條簡單題,呵呵 2006-02-19 01:27 
            是啊,忘記了,不可原諒的錯誤!~
              回復  更多評論
              
            # 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;
            }  回復  更多評論
              
            # re: 今天又過條簡單題,呵呵 2007-03-07 22:10 
            呵呵,因為那個時候我也是新手嘛,不過現在雖然老了,還是一只老菜鳥  回復  更多評論
              
            99久久精品国产一区二区蜜芽| 亚洲精品高清国产一线久久| 久久久青草久久久青草| 热99re久久国超精品首页| 久久天天躁狠狠躁夜夜2020 | 亚洲中文字幕无码久久2020| 久久久久亚洲精品无码蜜桃| 国内精品久久久久久久久电影网| 精品久久久久久国产| 成人资源影音先锋久久资源网| 久久伊人影视| 久久国产成人精品麻豆| 亚洲色大成网站www久久九| 久久国产福利免费| 国产精品久久久久影视不卡| 久久国产AVJUST麻豆| 日本精品久久久久中文字幕| 中文字幕无码精品亚洲资源网久久| 国产精品va久久久久久久| 久久精品a亚洲国产v高清不卡| 99精品国产免费久久久久久下载| 人人狠狠综合久久亚洲婷婷| 新狼窝色AV性久久久久久| 亚洲AⅤ优女AV综合久久久| 热99re久久国超精品首页| 久久超乳爆乳中文字幕| 亚洲中文字幕无码久久精品1| 亚洲国产成人精品女人久久久| 91精品国产91热久久久久福利| 亚洲精品无码久久久久| 亚洲av伊人久久综合密臀性色| 亚洲国产成人精品女人久久久 | 婷婷伊人久久大香线蕉AV| 亚洲伊人久久成综合人影院 | 中文字幕久久久久人妻| 久久精品国产男包| 久久久久久久久66精品片| 欧美黑人激情性久久| 国产精品中文久久久久久久| 波多野结衣久久| 亚洲乱码中文字幕久久孕妇黑人 |