不知两位版主为何现在不做题了,你们的帖子让我学到了很多东西,希望这个帖子继续下去,毕竟OJ上的题还有很多,我有能力的话会跟大家一起做题
熟能生巧
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX 1000003 int num[MAX]; char s[MAX]; int main() { while(scanf("%s", s) != EOF) { int len = strlen(s); int max = 0; int i = 0; int j = -1; while(i <= len) { if(j == -1 || s[i] == s[j]) { ++i; ++j; num[i-1] = j; if(j > max) max = j; } else { if(j == 0) j = -1; else j = num[j-1]; } } if(max == 0) printf("NO"); else for(int i = 0; i < max; ++i) printf("%c", s[i]); printf("\n"); memset(s, 0, sizeof(s)); memset(num, 0, sizeof(num)); } }
#include <stdio.h> int main() { int num = 0; double max[35], min[35]; while(scanf("%d", &num) != EOF) { for(int i = 0; i < 35; ++i) { max[i] = -1e10; min[i] = 1e10; } for(int i = 0; i < num; ++i) { double a, b, c, d, e; scanf("%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e); int j = 0; for(int A = -1; A < 2; A+=2) for(int B = -1; B < 2; B+=2) for(int C = -1; C < 2; C+=2) for(int D = -1; D < 2; D+=2) for(int E = -1; E < 2; E+=2) { double temp; temp = A*a + B*b + C*c + D*d + E*e; if(max[j] < temp) max[j] = temp; if(min[j] > temp) min[j] = temp; j++; } } double result = 0.0; for(int i = 0; i < 32; ++i) { if(result < max[i]-min[i]) result = max[i]-min[i]; } printf("%.2lf\n", result); } return 0; }
#include <stdio.h> #include <math.h> int isprime(long long int x) { long long int i; if (x==2||x==3) return 1; if (x>=4) { for (i=2; i<=(int)sqrt((double)x); i++) if (x%i==0) return 0; } return 1; } int main() { long long int m = 1, n = 1, i; while (m&&n) { scanf("%lld %lld", &m, &n); if (m&&n) { for (i=2; i<n; i++) { if ((m%i==0)&&isprime(i)) { printf("BAD %lld\n", i); break; } } if (i>=n) printf("GOOD\n"); } } return 0; }