What's the problem with the code below ?
Posted
by VaioIsBorn
on Stack Overflow
See other posts from Stack Overflow
or by VaioIsBorn
Published on 2010-03-23T19:50:16Z
Indexed on
2010/03/23
19:53 UTC
Read the original article
Hit count: 226
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
int i, s, g;
vector<int> a;
cin >> s;
for(i=1;i<=s;i++)
{
g = s;
if(g<10) a.push_back(g);
else {
vector<int> temp;
while(g > 0)
{
int k = g % 10;
g = g / 10;
temp.push_back(g);
}
for(int j=temp.size();j>0;j--)
{
a.push_back(temp[j]);
}
}
}
cout << a[s-1] << endl;
return 0;
}
What is wrong with the code above ? It doesn't give me the appropriate results.
The vector a is supposed to hold the values from 1, 2, 3...up to s such that a = 12345..910111213... and print to output a[s]. Ex if s=15 a=123456789101112131415 and a[15] = 2 .
If someone could tell me what's the problem
© Stack Overflow or respective owner