14点开始做,现在时间16:23。出错了,头好晕~~~

来源:互联网 发布:碳晶地暖垫 知乎 编辑:程序博客网 时间:2024/04/30 15:01

头晕,算法已经想好,写出来的程序有漏洞,没有按照我的想法来执行。头晕!我做别的题目了。

我的程序代码:

/ 

*
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;

bool pandun(char *ch1,char * ch2)
{
 int i=0,j=0,k,n;
 while(ch1[i]!='a')
  i++;
 while(ch2[j]!='a')
  j++;
 n=j-2;
 k=i-2;
 if(ch1[0]==ch2[n+1])
 {
  while(1)
  {
   if(ch1[k]!=ch2[n])
   {
    return true;
   }
   k--;
   n--;
   if(k==1&&n==0)
    return false;
  }
 }
 else
  return true;
}

int main()
{
 int t,n,k,i,j,ch,flag;
 char ch1[100],ch2[100],ch3[100];
 cin>>t;
 while(t)
 {
  cin>>n>>k;
  i=0;
  j=0;
  flag=1;
  memset(ch1,'a',sizeof(ch1));
  memset(ch2,'a',sizeof(ch2));
  memset(ch3,'0',sizeof(ch3));
  ch1[j]=k+'0';
  j++;
  while(j<100)
  {
   ch=ch1[j-1]-'0';
   ch*=n;
   if(!(ch/10))
   {
    if((ch%10+ch3[i])>'9')
    {
     ch3[i+1]=(ch%10+ch3[i]-'0')/10+'0';
     ch2[i]=(ch%10+ch3[i]-'0')%10+'0';
    }
    else
     ch2[i]=(ch%10)+ch3[i];
    i++;
   }
   else
   {
    if((ch%10+ch3[i])>'9')
    {
     ch3[i+1]=(ch%10+ch3[i]-'0')/10+'0';
     ch2[i]=(ch%10+ch3[i]-'0')%10+'0';
    }
    else
     ch2[i]=(ch%10)+ch3[i];
    ch3[i+1]=ch/10+'0';
    i++;
   }
   ch1[j]=ch2[i-1];
   j++;
   if(j==100)
    flag=0;
  }
  if(/*(ch1[j-2]-'0')*n<10&&*/flag)
   for(k=j-2;k>=0;k--)
    cout<<ch1[k];
  else
   cout<<"0";
  cout<<endl;
  t--;
 }
 return 0;
}