#include
#include
#include
#include
#include
#include
using namespace std;
int pow(int i,int j)
{
int sum=1;
for(int k=1; k<=j; k++)
{
sum*=i;
}
return sum;
}
int jinzhi_16(char *number)
{
char *p=number;
int sum=0;
int len=strlen(number);
int i=0;
int lone;
while(*p)
{
if(toascii(*p)>=65&&toascii(*p)<=70)
{
lone=toascii(*p)-55;
}
else
{
lone=*p-'0';
}
sum+=pow(16,len-i-1)*lone;
i++;
*p++;
}
return sum;
}
int jinzhi_1_10(char *number,int N)
{
char *p=number;
int sum=0;
int len=strlen(number);
int i=0;
int lone;
while(*p)
{
lone=*p-'0';
sum+=pow(N,len-i-1)*lone;
i++;
*p++;
}
return sum;
}
int is_reverse(char *number)
{
int len=strlen(number);
char *save_number=(char *)malloc(sizeof(char) *(strlen(number)));
strcpy(save_number,number);
reverse(save_number,save_number+len-1);
if(strcmp(save_number,number)==0)
{
return true;
}
}
int return_is_16(char *number)
{
char *p=number;
while(*p)
{
if(toascii(*p)>=65&&toascii(*p)<=91)
{
return true;
}
*p++;
}
}
int main()
{
int N;
cin>>N;
getchar();
char *number=(char *)malloc(sizeof(char) * 32);
gets(number);
int num;
if(N==16)
{
num=jinzhi_16(number);
}
else
{
num=jinzhi_1_10(number,N);
}
int count_step=0;
while(is_reverse(number)!=1)
{
int new_number;
reverse(number,number+strlen(number)-1);
new_number=sprintf(number,"%s",new_number);
num=new_number+num;
sprintf(number,"%d",num);
count_step++;
cout<if(count_step>=30)
{
cout<<"Impossible!";
return 0;
}
}
cout<<"STEP="<return 0;
}
#include
#include
int main() {
double pi,r;
int n,m;
#define eps 1e-5 // ; 这儿不能有分号
n = 0;
pi = 0;
m = 1;
do {
r = pi;
pi = r + 4.0*m/(2*n + 1);
n = n + 1;
m = -m;
}while(fabs(pi - r) > eps);
printf("%f,%d\n",pi,n);
return 0;
}
#define eps 1e-5这句后面不要分号。
输入法不对,打出来的“)”也不对