重写了PKU2897“Dramatic Multiplications”,AC了,重写后思路很清晰,果然不一样!
来源:互联网 发布:淘宝网足球 编辑:程序博客网 时间:2024/04/30 00:16
最近几天比较少更新Blog,原因是因为我连QQ都无法连上。昨天和前天加起来一共做了14道题,都是在zju的。因为我有zju的离线文件。可是最后在PKU上只AC了三道,加上我重写的这一道,一共AC了4道。我数了下,我还有8道提交了没AC。
我的程序代码:
/*
Dramatic Multiplications
Time Limit:1000MS Memory Limit:65536K
Total Submit:714 Accepted:216
Description
Hassan, helping with his younger brother's homework, found out that when you multiply 102564 by 4, its right-most digit moves to the left, and the other digits move one position to the right; i.e. 4 * 102564 = 410256. We call a number that has this property when multiplied by n, an n-dramatic number. For instance, 102564 and 128205 are both 4-dramatic. Given two one-digit numbers n and k, the goal is to find the smallest n-dramatic number that its rightmost digit is k.
Input
On the first line of the input, there is an integer t, which is the number of cases that follow. Each test case, is on a line by itself, and contains two integers n and k, where 1 <= n <= 9, and 1 <= k <= 9.
Output
For each test case, output a single integer on a line by itself, which is the smallest n-dramatic number that its rightmost digit is k. If no such number exists, output 0 instead.
Sample Input
2
4 5
2 1
Sample Output
128205
0
Source
Tehran 2005
*/
#include "iostream"
using namespace std;
int main()
{
int n,i,k,t,flag,j;
char str1[100],str2[100],str3[100];
cin>>t;
while(t)
{
memset(str1,'0',sizeof(str1));
memset(str2,'0',sizeof(str2));
memset(str3,'0',sizeof(str3));
i=0;
flag=0;
cin>>n>>k;
if(n<1||n>9||k<1||k>9)
return 0;
str1[i]=k+'0';
i++;
while(i<100)
{
str2[i-1]+=str3[i-1]-'0';
str2[i-1]+=((str1[i-1]-'0')*n)%10;
str3[i]+=((str1[i-1]-'0')*n)/10;
if(str2[i-1]>'9')
{
str2[i-1]-=10;
str3[i]+=1;
}
str1[i]=str2[i-1];
i++;
}
for(i=0;i+1<100;i++)
{
if(str3[i+1]=='0'&&str1[0]==str2[i]&&str1[i]!='0')
{
flag=1;
break;
}
}
if(flag)
{
for(j=i;j>=0;j--)
cout<<str1[j];
cout<<endl;
}
else
cout<<"0"<<endl;
t--;
}
return 0;
}
- 重写了PKU2897“Dramatic Multiplications”,AC了,重写后思路很清晰,果然不一样!
- 这个题目我重写了好几遍,虽然思路很清晰,但始终没有写出来,借鉴了一下别人的,日后再研究
- POJ 2897 Dramatic Multiplications
- 重写了equals方法后不一定要重写hashcode()
- 为什么重写了equals方法后,还要重写hashcode方法
- poj 2897 Dramatic Multiplications 模拟
- POJ 2897 Dramatic Multiplications 笔记
- 重写博客了
- 重写了书法字典
- 重写了一下gcrawler
- 开始重写小说了
- 重写了equals,为啥一定要重写hashcode
- 为什么重写了equals(),还要重写hashCode()?
- 覆盖,重写,重载,隐藏,多态的区别(一下子清晰了)
- 笔记本除尘后果然安静了
- 在重写了对象的equals方法后,还需要重写hashCode方法吗?
- 在重写了对象的equals方法后,还需要重写hashCode方法吗?
- 在重写了对象的equals方法后,还需要重写hashCode方法吗?
- 小析override & overload
- Linux内核编译详解
- 软件开发合同
- HTTP 请求转发、重定向
- 关于IIS的修复
- 重写了PKU2897“Dramatic Multiplications”,AC了,重写后思路很清晰,果然不一样!
- 爱不是一个坚强的理由
- 休息几天吧--放松
- Google对付桥页作弊的方法 - 供百度开发人员参考
- 告别学生时代,开始职业生涯
- JS表头冻结
- 2006-07-27 我又感冒了,我又做噩梦了.
- 通过Windows 2000专业版的注册表来配置系统服务
- 再见了,煤田~~~~