您的位置:首页 > 其它

poj 百练2799(基础题)

2012-05-16 10:00 246 查看
对于浮点数进行“对齐”

当成字符串来处理

#include <fstream>
#include <string.h>
#include <stdio.h>
#include <algorithm>

#define _cdebbug

using namespace std;

int main()
{
//重定向
#ifdef _cdebbug
freopen("F:\\input.txt","r",stdin );
#endif
char str[10001][51] ;
int floatpoint,i,j,n,k;
scanf("%d",&n);
memset(str,0,sizeof(char)*10001*51);

floatpoint = 0;

for (i = 0; i < n; ++i)
{
scanf("%s",str[i]);
for (j = 0; str[i][j] != '\0'; j++)
{
if (str[i][j] == '.')
break;
}
if (j > floatpoint)
floatpoint = j;
}

for (i = 0; i < n; ++i)
{
for (j = 0; str[i][j] != '\0'; j++)
if (str[i][j] == '.')
break;
for (k = 0; k < (floatpoint - j); ++k)
printf(" ");
printf( "%s\n" , str[i] );
}

//解除重定向关闭文件

#ifdef _cdebbug
fclose(stdin);
#endif
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: