`
caoruntao
  • 浏览: 467302 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

字符串:zoj 2476 Total Amount

 
阅读更多

【转】http://blog.csdn.net/zxy_snow/article/details/6158074

 

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <stack>
#include <float.h>
using namespace std;
stack <char> s;
int main()
{
	int n,i,k,len,d;
	char str[20],to[20];
	char ss[30];
	int ans,tmp;
	while( scanf("%d",&n) != EOF && n )
	{
		ans = 0;
		getchar();
		for(i=0; i<n; i++)
		{
			gets(str);
			len = strlen(str);
			d = 0;
			for(k=1; k<len; k++)
			{
				if( isdigit( str[k] ) )
					to[d++] = str[k];
			}
			to[d] = '/0';
			tmp = atoi(to);
			ans += tmp;
		}
		if( ans < 10 )
		{
			printf("$0.0%d/n",ans);
			continue;
		}
		if( ans < 100 )
		{
			printf("$0.%d/n",ans);
			continue;
		}
		sprintf(ss,"%d",ans);
		len = strlen(ss);
		s.push(ss[len-1]);
		s.push(ss[len-2]);
		s.push('.');
		int k = 0;
		for(i=len-3; i>=0; i--)
		{
			k++;
			s.push(ss[i]);
			if( k % 3 == 0 && i )
				s.push(',');
		}
		putchar('</p>);
		while( !s.empty() )
		{
			printf("%c",s.top());
			s.pop();
		}
		printf("/n");
	}
return 0;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics