UVA11549 Calculator Conundrum
来源:互联网 发布:ping 端口号 编辑:程序博客网 时间:2024/05/19 09:47
原文请访问我的博客:http://xiaoshig.sinaapp.com/?p=115
Alice got a hold of an old calculator that can display n digits. She was bored enough to come up with the following time waster.
She enters a number k then repeatedly squares it until the result overflows. When the result overflows, only the n most significant digits are displayed on the screen and an error flag appears. Alice can clear the error and continue squaring the displayed number. She got bored by this soon enough, but wondered:
“Given n and k, what is the largest number I can get by wasting time in this manner?”
Program Input
The first line of the input contains an integer t (1 ≤ t ≤ 200), the number of test cases. Each test case contains two integers n (1 ≤ n ≤ 9) and k (0 ≤ k < 10n) where n is the number of digits this calculator can display k is the starting number.
Program Output
For each test case, print the maximum number that Alice can get by repeatedly squaring the starting number as described.
Sample Input & Output
INPUT
21 62 99
OUTPUT999
#include<iostream>#include<set>#include<sstream>using namespace std;int next(int n,int k){stringstream ss;ss<<( long) k*k;string s=ss.str();if(s.length()>n)s=s.substr(0,n);int ans;stringstream ss2(s);ss2>>ans;return ans;}int main(){int t;cin>>t;while(t--){int n,k;cin>>n>>k;set<int> s;int ans=k;while(!s.count(k)){s.insert(k);if(k>ans)ans=k;k=next(n,k);}cout<<ans<<endl;}return 0;}
- Calculator Conundrum UVa11549
- UVA11549 Calculator Conundrum
- uva11549 - Calculator Conundrum
- UVa11549 - Calculator Conundrum (Floyd判圈法)
- uva11549 Calculator Conundrum【解法一】
- uva11549 Calculator Conundrum【解法二】
- uva11549 - Calculator Conundrum(计算机谜题)
- UVa11549 - Calculator Conundrum(Floyd判圈算法)
- 算法竞赛入门经典训练指南 例题1-19 计算器谜题 Calculator Conundrum uva11549
- CALCULATOR CONUNDRUM
- Calculator Conundrum
- Uva-11549 - Calculator Conundrum
- UVA 11549 Calculator Conundrum
- Uva-11549-Calculator Conundrum
- uva 11549 - Calculator Conundrum
- UVA 11549 Calculator Conundrum
- uva 11549 CALCULATOR CONUNDRUM
- UVA 11549 Calculator Conundrum
- 跟我学设计模式视频教程——面向对象理论,模板方法
- 跟我学设计模式视频教程——代理模式
- linux内核的编译
- #L面经#同主题阅读:L面经
- 怎么配置IP使得SSH能够连接到LINUX
- UVA11549 Calculator Conundrum
- leetcode 刷题之路 21 Search for a Range
- Linux恢复不可用交换分区
- ios 杂乱小总结
- An App a day——NFC小助手
- An App a day——RFID DEMO
- 1.7 C语言下的接口与结构体
- GCC的使用
- Java语言基础(算术运算符_2&赋值运算符)(s+=4与s=s+4的区别)