posts - 21,  comments - 9,  trackbacks - 0
不得不说poj 2305是一道进制转换的经典题目。一开始我没有考虑到整除的情况。所以总是WA。后来加了一个判断就AC了。
#include<iostream>
#include<cstring>
using namespace std;
char s1[1005],s2[15];
int main()
{
 int n;
 while(cin>>n&&n)
 {
  cin>>s1>>s2;
  __int64 a=0,b=0;int len1,len2;
  len1=strlen(s1);len2=strlen(s2);
  for(int i=0;i<len2;i++)
  {
   a*=n;
   a+=s2[i]-'0';
  }
  for(int j=0;j<len1;j++)
  {
   b*=n;
   b+=s1[j]-'0';
   if(b>=a)
    b%=a;
  }
  int k=0;
  if(b==0)
  {
   cout<<"0"<<endl;
   continue;
  }
  while(b!=0)
  {
   s2[k++]=b%n+'0';
   b/=n;
  }
  s2[k]='\0';
  int len=strlen(s2);
  for(k=len-1;k>=0;k--)
   cout<<s2[k];
  cout<<endl;
 }
 return 0;
}
posted on 2010-08-19 11:26 崔佳星 阅读(1131) 评论(0)  编辑 收藏 引用 所属分类: POJ

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜