Added some new files left out of last commit
This commit is contained in:
parent
938e75716c
commit
d1c11799f4
BIN
LiberationSans-Regular.ttf
Normal file
BIN
LiberationSans-Regular.ttf
Normal file
Binary file not shown.
47
itos.cpp
Normal file
47
itos.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "itos.h"
|
||||
#include <stack>
|
||||
#include <cstdlib>
|
||||
|
||||
using std::string;
|
||||
using std::stack;
|
||||
using std::abs;
|
||||
|
||||
string itos(int val)
|
||||
{
|
||||
string answer;
|
||||
stack<int> stk;
|
||||
int temp;
|
||||
|
||||
if (val < 0)
|
||||
{
|
||||
answer += "-";
|
||||
val = abs(val);
|
||||
}
|
||||
|
||||
while (val > 0)
|
||||
{
|
||||
temp = val % 10;
|
||||
stk.push(temp);
|
||||
val = val / 10;
|
||||
}
|
||||
|
||||
if (stk.empty()) return "0";
|
||||
|
||||
while (!stk.empty())
|
||||
{
|
||||
temp = stk.top();
|
||||
if (temp == 0) answer += '0';
|
||||
else if (temp == 1) answer += '1';
|
||||
else if (temp == 2) answer += '2';
|
||||
else if (temp == 3) answer += '3';
|
||||
else if (temp == 4) answer += '4';
|
||||
else if (temp == 5) answer += '5';
|
||||
else if (temp == 6) answer += '6';
|
||||
else if (temp == 7) answer += '7';
|
||||
else if (temp == 8) answer += '8';
|
||||
else if (temp == 9) answer += '9';
|
||||
stk.pop();
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
Loading…
Reference in New Issue
Block a user