USACO 2.3 The Longest Prefix
2011-05-05 20:06
405 查看
TASK: prefix
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3408 KB]
Test 2: TEST OK [0.000 secs, 3408 KB]
Test 3: TEST OK [0.000 secs, 3408 KB]
Test 4: TEST OK [0.000 secs, 3408 KB]
Test 5: TEST OK [0.000 secs, 3408 KB]
Test 6: TEST OK [0.702 secs, 3408 KB]
All tests OK.
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3408 KB]
Test 2: TEST OK [0.000 secs, 3408 KB]
Test 3: TEST OK [0.000 secs, 3408 KB]
Test 4: TEST OK [0.000 secs, 3408 KB]
Test 5: TEST OK [0.000 secs, 3408 KB]
Test 6: TEST OK [0.702 secs, 3408 KB]
All tests OK.
/* PROG: prefix ID: jiafeim1 LANG: C++ */ #include <algorithm> //#include <iostream> #include <fstream> #include <string.h> #include <stdio.h> using namespace std; char sub_string[202][15]; long len_sub_string[202]; long max_sub_len = 0; char str[200005]; bool can[200005]={false}; int top = 0; int main() { //std::ifstream fin("prefix.in"); // std::ofstream fout("prefix.out"); FILE* fin = fopen("prefix.in","r"); FILE* fout = fopen("prefix.out","w"); for(;;++top) { fscanf(fin,"%s",&sub_string[top][0]); if(sub_string[top][0] == '.') break; len_sub_string[top] = strlen(sub_string[top]); if(max_sub_len<len_sub_string[top]) max_sub_len = len_sub_string[top]; } char temp_str[80]; str[0]=0; while(fscanf(fin,"%s",temp_str)!=-1) strcat(str,temp_str); long len = strlen(str); long max = -1; for(long i = 0 ; i!=len;++i) { if(i-max>max_sub_len) break; char t = str[i+1]; str[i+1]=0; for(int now_sub = 0;now_sub!=top;++now_sub) { if(i+1<len_sub_string[now_sub]) continue; if((i-len_sub_string[now_sub] == -1 || can[i-len_sub_string[now_sub]]) && !strcmp(str+i+1-len_sub_string[now_sub],sub_string[now_sub])) { max = i; can[i]= true; break; } } str[i+1]=t; } fprintf(fout,"%ld\n",max+1); fclose(fin); fclose(fout); // fin.close(); //fout.close(); }
相关文章推荐
- USACO 2.3 The Longest Prefix (prefix)
- 【USACO 2.3】The Longest Prefix
- USACO 2.31 The Longest Prefix
- USACO 2.3 Longest Prefix(乱搞)
- USACO Section 2.3 The Longest Prefix - 一点点DP思想
- USACO 2.3.1 The Longest Prefix
- USACO section2.3 Longest Prefix题解&代码
- USACO 2.3.1The Longest Prefix
- USACO2.3.1 The Longest Prefix 题解
- USACO2.3.1 The Longest Prefix (prefix)
- USACO2.3 最长前缀 Longest Prefix(trie)
- USACO section 2.3 Longest Prefix(dp)
- USACO Section 2.3 The Longest Prefix
- USACO section 2.3 Longest Prefix(dp)
- USACO Section2.3 Longest Prefix 解题报告 【icedream61】
- USACO-Section 2.3 Longest Prefix (DP)
- USACO2.3.1 The Longest Prefix (prefix)
- USACO 2.3 Longest Prefix 题解
- USACO-Section2.3 Longest Prefix【动态规划】
- usaco Longest Prefix