좀 바보같지 않냐?
#include <iostream>
#include <sstream>
using namespace std;
#define is_alphabet(c) ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z')
#define is_numeric(c) ((c) >= '0' && (c) <= '9')
void translate(istream& is, ostream& os)
{
int numeric_mode, number;
numeric_mode = number = 0;
for(int c; c = is.get();)
{
if (is_numeric(c)) numeric_mode = 1, number = number * 10 + c - '0';
else
{
if (numeric_mode) os << (number + 5);
numeric_mode = number = 0;
if (is_alphabet(c)) os << char(c ^ 32);
else if (c != EOF) os << "[" << c << "]";
else break;
}
}
os << endl;
}
int main()
{
translate(cin, cout);
stringstream ss;
ss << "hello world";
translate(ss, cout);
return 0;
}
결과:
<< 13Ace of Base 999
>> 18aCE[32]OF[32]bASE[32]1004
HELLO[32]WORLD
getch 쓸것도 아니고 딱히 레포트 수준에서 buffered io 피해 다닐 일이 읍쥐.
좋은 곳에 쓰겠습니다