• <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年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 217830
            • 排名 - 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 閱讀(922) 評論(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热精品久久只有精品| 久久天天躁夜夜躁狠狠躁2022| 无码人妻少妇久久中文字幕| 久久精品18| 日日躁夜夜躁狠狠久久AV| 久久99国产亚洲高清观看首页 | 久久精品国产一区二区电影| 久久亚洲电影| 国产亚洲欧美成人久久片| 夜夜亚洲天天久久| 久久青青色综合| 99久久精品国产麻豆| 色欲综合久久躁天天躁| 午夜天堂av天堂久久久| 99久久精品九九亚洲精品| 久久久SS麻豆欧美国产日韩| 久久国产乱子伦精品免费强| 久久亚洲精品无码aⅴ大香 | 久久久久国产精品熟女影院| 久久久国产精品| 久久婷婷五月综合97色一本一本| 精品国产热久久久福利| 久久精品国产亚洲av水果派 | 久久国产精品-国产精品| 久久久高清免费视频| 国产91久久综合| 国产婷婷成人久久Av免费高清 | 久久精品国产一区二区三区日韩| 色婷婷噜噜久久国产精品12p| 久久精品成人免费网站| 日产精品久久久久久久性色| 久久精品综合网| 少妇人妻综合久久中文字幕| 久久国产免费直播| 天天爽天天爽天天片a久久网| 久久精品国产精品青草app| 精品久久久一二三区| 伊人伊成久久人综合网777| 一本综合久久国产二区| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 |