Created
May 1, 2012 22:00
-
-
Save enamcse/2571774 to your computer and use it in GitHub Desktop.
UVa 100 113 10035 10055 10071 10079 10323 10346 10370
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int cycle_length (int n); | |
int main() | |
{ | |
int i, j, k, large, n, p, q; | |
while(scanf("%d %d", &i, &j) == 2) | |
{ | |
if (i > 0 && j > 0) | |
{ | |
q = i > j ? i : j; | |
p = i < j ? i : j; | |
large = 0; | |
for (k = p; k <= q; k++) | |
{ | |
n = cycle_length(k); | |
if (n > large) large = n; | |
} | |
printf("%d %d %d\n", i, j, large); | |
} | |
} | |
return 0; | |
} | |
int cycle_length(int x) | |
{ | |
int i; | |
if(x != 1) | |
{ | |
for (i = 1; x != 1; ++i) | |
{ | |
if (x % 2 == 1) x = (3 * x + 1); | |
else x = x / 2; | |
} | |
} | |
else i = 1; | |
return i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int cycle_length (int n); | |
int main() | |
{ | |
int i, j, k, large, n, p, q; | |
while(scanf("%d %d", &i, &j) == 2) | |
{ | |
if (i > 0 && j > 0) | |
{ | |
q = i > j ? i : j; | |
p = i < j ? i : j; | |
large = 0; | |
for (k = p; k <= q; k++) | |
{ | |
n = cycle_length(k); | |
if (n > large) large = n; | |
} | |
printf("%d %d %d\n", i, j, large); | |
} | |
} | |
return 0; | |
} | |
int cycle_length(int x) | |
{ | |
int i; | |
if(x != 1) | |
{ | |
for (i = 1; x != 1; ++i) | |
{ | |
if (x % 2 == 1) x = (3 * x + 1); | |
else x = x / 2; | |
} | |
} | |
else i = 1; | |
return i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main() | |
{ | |
char num1[100], num2[100]; | |
int i, j, len1, len2, n1, n2, sum, carry, count; | |
scanf("%s %s", num1, num2); | |
len1 = strlen(num1); | |
len2 = strlen(num2); | |
while((len1 != 1 || num1[0] != '0') || (len2 != 1 || num2[0] != '0')) | |
{ | |
carry = count = 0; | |
for (i = len1 - 1, j = len2 - 1; i >= 0 || j >= 0; --i, --j) | |
{ | |
n1 = (int) (num1[i] - '0'); | |
n2 = (int) (num2[j] - '0'); | |
if (i < 0) n1 = 0; | |
else if (j < 0) n2 = 0; | |
sum = n1 + n2 + carry; | |
carry = 0; | |
if (sum > 9) | |
{ | |
carry = 1; | |
count++; | |
} | |
} | |
if(count == 0) printf("No carry operation.\n"); | |
else if (count == 1) printf("1 carry operation.\n"); | |
else printf("%d carry operations.\n", count); | |
scanf("%s %s", num1, num2); | |
len1 = strlen(num1); | |
len2 = strlen(num2); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
long long int a, b; | |
while(scanf("%lld %lld", &a, &b) == 2) | |
{ | |
if (a >= b)printf("%lld\n", a - b); | |
else printf("%lld\n", b - a); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int v,s,t; | |
while(scanf("%d %d", &v, &t) == 2) | |
{ | |
s = 2 * v * t; | |
printf("%d\n", s); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
long long int n, sum = 0, i; | |
scanf("%lld", &n); | |
while (n >= 0) | |
{ | |
sum = 1; | |
for (i = 0; i <= n; i++) | |
sum += i; | |
printf("%lld\n", sum); | |
scanf("%lld", &n); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
long long int pizza (long long int n, long long int sum); | |
int main() | |
{ | |
long long int n, sum = 0; | |
scanf("%lld", &n); | |
while (n >= 0) | |
{ | |
printf("%lld\n", pizza(n, sum)); | |
scanf("%lld", &n); | |
} | |
return 0; | |
} | |
long long int pizza (long long int n, long long int sum) | |
{ | |
if (n == 0) return 1; | |
sum = n + pizza(n - 1, sum); | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int n; | |
while(scanf("%d", &n) == 1) | |
{ | |
if (n < 0) | |
{ | |
if (n % 2 == 0) printf("Underflow!\n"); | |
else printf("Overflow!\n"); | |
} | |
else if (n < 8) printf("Underflow!\n"); | |
else if (n > 13) printf("Overflow!\n"); | |
else switch (n) | |
{ | |
case 8: | |
printf("40320\n"); | |
break; | |
case 9: | |
printf("362880\n"); | |
break; | |
case 10: | |
printf("3628800\n"); | |
break; | |
case 11: | |
printf("39916800\n"); | |
break; | |
case 12: | |
printf("479001600\n"); | |
break; | |
case 13: | |
printf("6227020800\n"); | |
break; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int n; | |
while(scanf("%d", &n) == 1) | |
{ | |
if (n < 0) | |
{ | |
if (n % 2 == 0) printf("Underflow!\n"); | |
else printf("Overflow!\n"); | |
} | |
else if (n < 8) printf("Underflow!\n"); | |
else if (n > 13) printf("Overflow!\n"); | |
else switch (n) | |
{ | |
case 8: | |
printf("40320\n"); | |
break; | |
case 9: | |
printf("362880\n"); | |
break; | |
case 10: | |
printf("3628800\n"); | |
break; | |
case 11: | |
printf("39916800\n"); | |
break; | |
case 12: | |
printf("479001600\n"); | |
break; | |
case 13: | |
printf("6227020800\n"); | |
break; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int n, n1, k, i, m, count; | |
while (scanf("%d %d", &n, &k) == 2) | |
{ | |
count = n; | |
n1 = n; | |
while (n1 >= k) | |
{ | |
count += n1 / k; | |
n1 = n1 / k + n1 % k; | |
} | |
printf("%d\n", count); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int C, N, num[1000], i, j, count; | |
double sum, percent[1000], avg; | |
while(scanf("%d", &C) == 1) | |
{ | |
for (i = 0; i < C; ++i) | |
{ | |
sum = 0; | |
count = 0; | |
scanf("%d", &N); | |
for (j = 0; j < N; ++j) | |
{ | |
scanf("%d", &num[j]); | |
sum+= num[j]; | |
} | |
avg = sum / N; | |
for (j = 0; j < N; ++j) | |
if (num[j] > avg) ++count; | |
percent[i] = 100 * (double)count / N; | |
} | |
for (i = 0; i < C; ++i) | |
printf("%.3lf\%c\n", percent[i], '%'); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int main() | |
{ | |
double n, p, x, k; | |
while (scanf("%lf %lf", &n, &p) == 2) | |
{ | |
x = 1 / n; | |
k = pow(p, x); | |
printf("%.0lf\n", k); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment