//2015-01
#include <iostream>
#include <string>
using namespace std;
const int N = 110;
int main()
{
string s;
string a[N];
getline(cin, s);
int r = 0;
int sum = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '-' && isdigit(s[i + 1]))
{
int j = i + 1;
while (isdigit(s[j]))
{
a[r] += s[j];
j++;
}
sum = sum - stoi(a[r]);
i = j;
r++;
continue;
}
if (isdigit(s[i]))
{
int j = i;
while (isdigit(s[j]))
{
a[r] += s[j];
j++;
}
sum = sum + stoi(a[r]);
r++;
i = j;
continue;
}
}
cout << r << ' ' << sum << endl;
return 0;
}
hdu笔试2015-01字符串求和
最新推荐文章于 2024-09-01 16:42:17 发布