water~1

1491 단어 물 문제
poj1503
http://poj.org/problem?id=1503

#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

string ans="0";
string inputs[107];
int counts;

string adds(const string a,const string b)
{
	string c;
	int temp=0;
	int i,j;
	for(i=a.size()-1,j=b.size()-1;i>=0 && j>=0;i--,j--)
	{
		c.append(1,((a[i]+b[j]-96+temp) % 10)+48);
		temp=(a[i]+b[j]-96+temp)/10;
	}
	if(i<0)
	{
		
		while(j>=0)
		{
			c.append(1,(b[j]-48+temp)%10+48);
			temp=(b[j]-48+temp)/10;
			j--;
		}
	}
	else
	{
	
		while(i>=0)
		{		
			c.append(1,(a[i]-48+temp)%10+48);
			temp=(a[i]-48+temp)/10;
			i--;		
		
		}
	}
	if(temp)
		c.append(1,temp+48);

	
	reverse(c.begin(),c.end());
		
	return c;
}

void waterit()
{
	for(int i=0;i<counts;i++)
		ans=adds(ans,inputs[i]);
	cout<<ans<<endl;
}

int main()
{
//	ifstream cin("1.txt");
	int i=0;

	while(cin>>inputs[i])i++;
	counts=i-1;
	
	waterit();


	
	return 0;
};

좋은 웹페이지 즐겨찾기