1.13.14

來源:互聯網
上載者:User

標籤:eof   namespace   color   scan   size   條件   std   sizeof   str   

14:求滿足條件的3位元

描述

編寫程式,按從小到大的順序尋找同時符合條件1和2的所有3位元,條件為:
1.該數為完全平方數
2.該數至少有2位元字相同
例如,100同時滿足上面兩個條件。

輸入輸入一個數n,n的大小不超過實際滿足條件的3位元的個數。輸出輸出為第n個滿足條件的3位元(升序)範例輸入

1

範例輸出

100
 1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int k(int n) 7 { 8     int z,a[10]; 9     memset(a,0,sizeof(a));10     while(n>0)11     {12         13         a[n%10]++;14         n/=10;15     }16     sort(a,a+10);17     return a[9];18 }19 bool ss(int n)20 {21     int x=sqrt(n);22     if(x*x==n) return true;23     return false;24 }25 int main()26 {27     int n,x=0,y=1,z;28     scanf("%d",&n);29 30     while(x<n)31     {32         if(k(y)>=2&&ss(y)==true)33         {34             x++;35             z=y;36         }37         y++;38     }39     printf("%d",z);40     return 0;41 }

 

1.13.14

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.