有点小无聊,秒杀了几道简单题
1113 公式计算
//
ZOJ 1113
#include < stdio.h >
int main()
{
int i,j;
double e = 2.5 ,dived = 2 ;
printf("n e/n- -----------/n0 1/n1 2/n2 2/.5/n");
for (i = 3 ;i <= 9 ;i ++ )
{
dived *= i;
e += 1 / dived;
if (i > 2 )
printf( " %d %.9lf/n " , i, e);
}
}
#include < stdio.h >
int main()
{
int i,j;
double e = 2.5 ,dived = 2 ;
printf("n e/n- -----------/n0 1/n1 2/n2 2/.5/n");
for (i = 3 ;i <= 9 ;i ++ )
{
dived *= i;
e += 1 / dived;
if (i > 2 )
printf( " %d %.9lf/n " , i, e);
}
}
1115 数位根
这道题AC了以后就想骂人,谁这么变态出的数据,题目简单到没话说,却让我WA了两下,原因是OJ上输入的数字位数太大了,输入时要用字符串的方式才能过。
#include
<
stdio.h
>
#include < string .h >
int droot( int in )
{
int n,i;
int re = 0 ;
char str[ 20 ];
sprintf(str, " %d " , in );
n = strlen(str);
for (i = 0 ;i < n;i ++ )
{
re += str[i] - 48 ;
}
if (re > 9 )
return droot(re);
else
return re;
}
int main()
{
// freopen("1115.txt","r",stdin);
int in ,n,i;
char str[ 1005 ];
while (scanf( " %s " , & str) != EOF && str[ 0 ] != ' 0 ' )
{
in = 0 ;
n = strlen(str);
for (i = 0 ;i < n;i ++ )
{
in += str[i] - 48 ;
}
printf( " %d/n " , droot( in ));
}
// fclose(stdin);
return 0 ;
}
#include < string .h >
int droot( int in )
{
int n,i;
int re = 0 ;
char str[ 20 ];
sprintf(str, " %d " , in );
n = strlen(str);
for (i = 0 ;i < n;i ++ )
{
re += str[i] - 48 ;
}
if (re > 9 )
return droot(re);
else
return re;
}
int main()
{
// freopen("1115.txt","r",stdin);
int in ,n,i;
char str[ 1005 ];
while (scanf( " %s " , & str) != EOF && str[ 0 ] != ' 0 ' )
{
in = 0 ;
n = strlen(str);
for (i = 0 ;i < n;i ++ )
{
in += str[i] - 48 ;
}
printf( " %d/n " , droot( in ));
}
// fclose(stdin);
return 0 ;
}
1295 反转输出字符串
注意最基本的输入方式就OK
#include
<
stdio.h
>
int main()
{
// freopen("1295.txt","r",stdin);
int n,i,count;
char str[ 100 ],c;
scanf( " %d " , & n);
scanf( " %c " , & c);
for (i = 1 ;i <= n;i ++ )
{
count = 0 ;
while (scanf( " %c " , & str[count]) != EOF && str[count] != ' ' )
count ++ ;
count -- ;
while (count >= 0 )
printf( " %c " , str[count -- ]);
printf( "/n " );
}
// fclose(stdin);
return 0 ;
}
int main()
{
// freopen("1295.txt","r",stdin);
int n,i,count;
char str[ 100 ],c;
scanf( " %d " , & n);
scanf( " %c " , & c);
for (i = 1 ;i <= n;i ++ )
{
count = 0 ;
while (scanf( " %c " , & str[count]) != EOF && str[count] != ' ' )
count ++ ;
count -- ;
while (count >= 0 )
printf( " %c " , str[count -- ]);
printf( "/n " );
}
// fclose(stdin);
return 0 ;
}