首页 › 题库 › C/C++编程考级 › C/C++编程一级 › 简答题
简答题 偏难
#7451

求满足条件的3位数(2024.3一级) 编写程序,按从小到大的顺序寻找同时符合条件1和2的所有3位数,条件为: 1.该数为完全平方数 2.该数至少有2位数字相同…

求满足条件的3位数(2024.3一级)

编写程序,按从小到大的顺序寻找同时符合条件1和2的所有3位数,条件为:

1.该数为完全平方数

2.该数至少有2位数字相同

例如,100同时满足上面两个条件。

输入

输入一个数n,n的大小不超过实际满足条件的3位数的个数。

输出

输出为第n个满足条件的3位数(升序)


样例输入

1

样例输出

100
未登录也能判分,登录后才会记录
答案与解析
正确答案:<pre class="brush:cpp;toolbar:false">// 参考答案1 #include &lt;bits/stdc++.h&gt; using namespace std; int a[1005]; int s = 1; int main() {   int x;   cin &gt;&gt; x;   if (x == 1)     cout &lt;&lt; 100;   if (x == 2)     cout &lt;&lt; 121;   if (x == 3)     cout &lt;&lt; 144;   if (x == 4)     cout &lt;&lt; 225;   if (x == 5)     cout &lt;&lt; 400;   if (x == 6)     cout &lt;&lt; 441;   if (x == 7)     cout &lt;&lt; 484;   if (x == 8)     cout &lt;&lt; 676;   if (x == 9)     cout &lt;&lt; 900; }</pre><pre class="brush:cpp;toolbar:false">// 参考答案2 #include &lt;bits/stdc++.h&gt; using namespace std; int main() { int n,a; cin&gt;&gt;n; a=0; for(int i=100,x;i&lt;=999;i++){ x=sqrt(i); if(x*x==i&amp;&amp;(i%10==i/10%10 || i/10%10==i/100 ||i%10==i/100)){ a++; if(a==n){ cout&lt;&lt;i;return 0; } } } return 0; }</pre>
这道题暂未补解析。