Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Forked from enamcse/11219 How old are you.c
Last active August 29, 2015 14:23
Show Gist options
  • Save shohan4556/177bff3474142185f4a0 to your computer and use it in GitHub Desktop.
Save shohan4556/177bff3474142185f4a0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main()
{
int month[2], day[2], year[2], i, t, age;
scanf("%d", &t);
for (i = 1; i <= t; ++i)
{
scanf("%d/%d/%d", &day[0], &month[0], &year[0]);
scanf("%d/%d/%d", &day[1], &month[1], &year[1]);
if (year[1] > year[0]) printf("Case #%d: Invalid birth date\n", i);
else if (year[1] == year[0] && month[1] > month[0]) printf("Case #%d: Invalid birth date\n", i);
else if (year[1] == year[0] && month[1] == month[0] && day[1] > day[0]) printf("Case #%d: Invalid birth date\n", i);
else
{
age = year[0] - year[1];
if (month[0] < month[1]) age--;
else if (month[0] == month[1] && day[1] > day[0]) age--;
if (age > 130) printf("Case #%d: Check birth date\n", i);
else printf("Case #%d: %d\n", i, age);
}
}
return 0;
}
#include <stdio.h>
int main()
{
int i, l, m, sum, n;
while(scanf("%d", &n) == 1)
{
if (n <= 0) break;
l = n;
sum = 0;
for (i = 1; i <= 10; i++)
{
m = l % 10;
l = l / 10;
sum += m;
}
if (sum > 9)
{
l = sum;
sum = 0;
for (i = 1; i <= 2; i++)
{
m = l % 10;
l = l / 10;
sum += m;
}
}
if (sum > 9)
{
l = sum;
sum = 0;
for (i = 1; i <= 2; i++)
{
m = l % 10;
l = l / 10;
sum += m;
}
}
printf("%d\n", sum);
}
return 0;
}
#include <stdio.h>
int main()
{
long int i, t, x, y, z;
scanf("%ld", &t);
for (i = 1; i <= t; i++)
{
scanf("%ld %ld %ld", &x, &y, &z);
if (x>0&&y>0&&z>0)
{
if (x+y<=z || y+z<=x || x+z<=y) printf("Case %d: Invalid\n", i);
else if (x == y && y == z) printf("Case %d: Equilateral\n", i);
else if ((x == y && x != z) || (y == z && y != x) || (x == z && z != y))
printf("Case %d: Isosceles\n", i);
else printf("Case %d: Scalene\n", i);
}
else printf("Case %d: Invalid\n", i);
}
return 0;
}
#include <stdio.h>
int main()
{
int i, t, n, mod, res;
scanf("%ld", &t);
for (i = 0; i < t; ++i)
{
scanf("%d", &n);
res = n * 63;
res += 7492;
res *= 5;
res -= 498;
res /= 10;
if (res < 0) res = -res;
mod = res % 10;
printf("%d\n", mod);
}
return 0;
}
#include <stdio.h>
int main()
{
int hw, i = 1, pastes, count;
scanf("%d", &hw);
while (hw > 0)
{
pastes = 1;
count = 2;
if (hw == 1) pastes = 0;
else if (hw == 2) pastes = 1;
else while (hw > count)
{
pastes++;
count = count * 2;
}
printf("Case %d: %d\n", i++, pastes);
scanf("%d", &hw);
}
return 0;
}
#include <stdio.h>
int main()
{
int hw, i = 1, pastes, count;
scanf("%d", &hw);
while (hw > 0)
{
pastes = 1;
count = 2;
if (hw == 1) pastes = 0;
else if (hw == 2) pastes = 1;
else while (hw > count)
{
pastes++;
count = count * 2;
}
printf("Case %d: %d\n", i++, pastes);
scanf("%d", &hw);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
int i, j, n, len1, len2, flag;
char a[40][20];
scanf("%d", &n);
for (i = 0; i < (2 * n); i += 2)
{
scanf("%[^\n] %[^\n]", a[i], a[i + 1]);
len1 = strlen(a[i]);
len2 = strlen(a[i + 1]);
if (len1 == len2)
{
flag = 1;
for (j = 0; j < len1; ++j)
{
if(a[i][j] != a[i + 1][j])
{
if (tolower(a[i][j]) == 'a' || tolower(a[i][j]) == 'e' || tolower(a[i][j]) == 'i' ||
tolower(a[i][j]) == 'o' || tolower(a[i][j]) == 'u')
{
if (tolower(a[i + 1][j]) != 'a' && tolower(a[i + 1][j]) != 'e' && tolower(a[i + 1][j]) != 'i' &&
tolower(a[i + 1][j]) != 'o' && tolower(a[i + 1][j]) != 'u') flag = 0;
}
}
}
if (flag == 1) printf("Yes\n");
else printf("No\n");
}
else printf("No\n");
}
return 0;
}
#include <stdio.h>
int main()
{
int a, b, c, max, min, n, i;
scanf("%d", &n);
for (i = 0; i < n; ++i)
{
scanf("%d %d %d", &a, &b, &c);
min = a < b ? (c < a ? c : a) : (c < b ? c : b);
max = a > b ? (c > a ? c : a) : (c > b ? c : b);
if ((a == min || a == max) && (b == min || b == max)) printf("Case %d: %d\n", i + 1, c);
else if ((a == min || a == max) && (c == min || c == max)) printf("Case %d: %d\n", i + 1, b);
else if ((c == min || c == max) && (b == min || b == max)) printf("Case %d: %d\n", i + 1, a);
}
return 0;
}
#include <stdio.h>
int main()
{
int t, n, up, down, now, then, i, j;
scanf("%d", &t);
for (i = 0; i < t; i++)
{
up = 0;
down = 0;
scanf("%d", &n);
scanf("%d", &now);
for (j = 1; j < n; j++)
{
then = now;
scanf("%d", &now);
if (now > then) up++;
else if (then > now) down++;
}
printf("Case %d: %d %d\n", i + 1, up, down);
}
return 0;
}
#include <stdio.h>
int main()
{
int a, b, c, d, e, f, g, i, n, m, p, q, sum;
while (scanf("%d", &n) == 1)
{
for (i = 1; i <= n; ++i)
{
scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g);
p = (e > f) ? ((g > e) ? g : e) : ((g > f) ? g : f);
q = (p == e) ? ((f > g) ? f : g) : ((p == f) ? ((e > g) ? e : g) : ((e > f) ? e : f));
m = (p + q) / 2;
sum = a + b + c + d + m;
if (sum >= 90) printf("Case %d: A\n", i);
else if (sum >= 80) printf("Case %d: B\n", i);
else if (sum >= 70) printf("Case %d: C\n", i);
else if (sum >= 60) printf("Case %d: D\n", i);
else printf("Case %d: F\n", i);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n, i, j, a[50][10000], h[50], len[50];
char ch;
scanf("%d ", &n);
for (i = 0; i < n; ++i)
{
h[i] = 0;
ch = '0';
for (j = 0; ch != '\n'; ++j)
{
scanf("%d", &a[i][j]);
ch = getchar();
}
len[i] = j;
for (j = 0; j < len[i]; ++j)
if ( h[i] < a[i][j]) h[i] = a[i][j];
}
for (i = 0; i < n; ++i)
printf("Case %d: %d\n", i+1, h[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment