Skip to content

Instantly share code, notes, and snippets.

@Eric-Bro
Created February 20, 2012 13:54
Show Gist options
  • Save Eric-Bro/1869319 to your computer and use it in GitHub Desktop.
Save Eric-Bro/1869319 to your computer and use it in GitHub Desktop.
Holy shit..
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
int is_digit(char c)
{
return (c >= '0' && c <= '9');
}
int main()
{
int count = 0, num = 0, i = 0;
char c;
char tmp[255];
memset(&tmp, '\0', sizeof(tmp));
scanf("%d", &count);
char **strings = malloc(sizeof(*strings) * count);
for (i = 0; i < count; i++){
strings[i] = malloc(sizeof(char) * 255);
memset(strings[i], '\0', sizeof(strings[i]));
}
for (i = 0; i < count; i++) {
int k = 0;
for (k = 0; !is_digit((c = getchar())); k++) {
tmp[k] = c;
}
int m, p,it;
m = c - '0';
scanf("%d %d", &p, &it);
if (m > 3 && p > 3 && it > 3) {
tmp[k-1] = '\0';
strcpy(strings[num], tmp);
++num;
}
memset(&tmp, '\0', sizeof(tmp));
}
for (i = 0; i < num; i++) {
int k =0, len = strlen(strings[i]);
for (k = 0; k < len; k++) {
if (strings[i][k] == ' ' && k == 0) continue;
if (strings[i][k] == '\n') continue;
printf("%c", strings[i][k]);
}
printf("\n");
free(strings[i]);
}
free(strings);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment