Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
晕了,还是WA#include <cstdio> #include <cstring> char word1[2000], word2[2000]; int GetGCD(int a, int b) { int temp; while (b > 0) { temp = b; b = a % b; a = temp; } return a; } void main() { FILE *fi = stdin; // fi = fopen("1580.txt", "r"); fscanf(fi, "%s", word1); while (word1[0] != '-') { fscanf(fi, "%s", word2); int len1 = (int)strlen(word1); int len2 = (int)strlen(word2); if (len1 > len2) { char strSwap[2000]; strcpy(strSwap, word1); strcpy(word1, word2); strcpy(word2, strSwap); int intSwap = len1; len1 = len2; len2 = intSwap; } int common; int max = 0; for (int head = 0; head < len2 - max; head++) { common = 0; for (int i = 0; i + head < len2 && i < len1; i++) { if (word1[i] == word2[i + head]) { common++; } } if (common > max) { max = common; } } int intGCD = GetGCD(max * 2, (int)strlen(word1) + (int)strlen(word2)); int up = max * 2 / intGCD; int down = (int)(strlen(word1) + strlen(word2)) / intGCD; printf("appx(%s,%s) = ", word1, word2); if (up == 0) { printf("0\n"); } else if (up == down) { printf("1\n"); } else { printf("%d/%d\n", up, down); } fscanf(fi, "%s", word1); } fclose(fi); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator