題目 http://luckycat.kshs.kh.edu.tw/homework/q445.htm
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int Sum(string str)
{
stringstream ss;
int A=0;
int Sum=0;
for(int i=0; i<str.length(); i++)
{
ss << str[i];
ss >> A;
Sum = Sum + A;
ss.clear();
}
return Sum;
}
int main(int argc, char *argv[])
{
//cout << Sum("1234") << endl;
string GetNum = "";
string Line = "";
string Target = "0123456789";
ifstream infile("input.txt",ios::in);
int Time = 0;
while(!infile.eof())
{
getline(infile,Line);
Line = Line + "!";
for(int i=0; i<Line.length(); i++)
{
if(Target.find(Line[i]) != -1)
{
GetNum = GetNum + Line[i];
}
else
{
if(Line[i] == '!')
{
cout << endl;
}
else
{
Time = Sum(GetNum);
for(int j=0; j<Time; j++)
{
if(Line[i] == 'b')
{
cout << " ";
}
else
{
cout << Line[i];
}
}
GetNum = "";
}
}
}
}
cout << "Press the enter key to continue ...";
cin.get();
return EXIT_SUCCESS;
}
沒有留言:
張貼留言