⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usaco_prefix.cpp

📁 usaco自己做的1到5章的代码
💻 CPP
字号:
/*
ID: wangyuc2
PROG: prefix
LANG: C++
*/ 
#include <fstream>
#include <iostream>
#include <memory>
#include <algorithm>
using namespace std;

ifstream fin("prefix.in");
ofstream fout("prefix.out");

int main()
{   
   char t[200][11];
   char s[200005];
   bool st[200005];
   char s1[11];
   char ch;
   int i,j,k,p,m,n,end;
   bool flag;
   flag=false; 
   i=0;
   memset(st,false,sizeof(st));
   do{
       fin>>t[i];
       i++;
       }while(strcmp(t[i-1],"."));
   m=i-1;    i=0;                       // the number of primitives;
   while(!fin.eof())
   {
       fin>>ch;
       if(ch<='Z' && ch>='A')  {s[i]=ch;
       i++;}
   }
   i--;
   s[i]='\0';
  // fout<<s;
   end=0;
   for(i=0;!flag && i<=end;i++)
   {
	   if(i==0 || st[i]){
		  for(j=0;j<m;j++)
		  {
			strncpy(s1,s+i,strlen(t[j]));
			s1[strlen(t[j])]='\0';
			if(!strcmp(t[j],s1))
			{
				st[i+strlen(t[j])]=true;
				if(i+strlen(t[j])>end) end=i+strlen(t[j]);
			}
		  }
   
	   }
   }
   fout<<end<<endl;
  //system("PAUSE");
   return 0;
}

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -