Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Last active August 29, 2015 14:12
Show Gist options
  • Save cengiz-io/03ce722669b876b898ed to your computer and use it in GitHub Desktop.
Save cengiz-io/03ce722669b876b898ed to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
#include <fstream>
#include <stack>
using namespace std;
int main(int argc, char *argv[]) {
ifstream datafile(argv[1]);
string line;
while (getline(datafile, line)) {
if (line.length() < 1) {
cout << endl;
continue;
}
stack<string> tokens;
istringstream stream(line);
string token;
while (getline(stream, token, ' ')) {
tokens.push(token);
};
istringstream convert(tokens.top());
unsigned int mth;
convert >> mth;
tokens.pop();
if (mth > tokens.size()) {
cout << endl;
continue;
}
for (unsigned int l = 1; l < mth; l++) {
tokens.pop();
}
cout << tokens.top() << endl;
}
return 0;
}
e r u p x h m o g b d f t n z w j a 11
m h j 19
o x s g r q c p z t 9
s y c p x j a w e r z k t o i 20
l k x o z f q i v c j m e d s t g a h w y n 14
o n h l p u z j v d b m r i y s c w e q g 25
h b t x p 11
l v n c w e j x a k 19
r h z w y a 16
y t e o w v i l d n j c s 25
n r y p i w b m z c a h l t g k s j d q x o v 14
q c h o a j n k y t f e w m r v l s p g b d u i 23
d a f 4
q x l m n o v f p j w d a g i 3
y i w b c r v e m o n p d j 24
p s o j m d t n x f 21
z b y v h j u r o d k g c t p x s m l q f a e i n 4
u w t e f s g a p m j y v o c x h k n d r l 12
x z v b m 24
o g b a s k v t f i 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment