예제 #1
0
int main ()
{
  freopen ("rle.in", "rt", stdin);
  freopen ("rle.out", "wt", stdout);

  scanf ("%s", rle);
  un_rle ();
#ifdef _DBG_
  for (int i = 0; i < num; i++)
    printf ("%c %I64d-%I64d (%d)\n", str[i].c, str[i].a, str[i].b, str[i].len);
#endif
  
  run_kmp ();

#ifdef _DBG_
  printf ("!\n");
  for (int i = 0; i < nkmp; i++)
    printf ("%I64d %d %I64d-%I64d (%d)\n", kmp[i].first, kmp[i].delta, kmp[i].a, kmp[i].b, kmp[i].len);
#endif
  int n;
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
  {
    __int64 a;
    scanf ("%I64d", &a);
    printf ("%I64d\n", get_answer (a - 1));
//    printf ("%d\n", bin_search (a - 1));
  }

  return 0;
}
예제 #2
0
파일: pmt.cpp 프로젝트: gppeixoto/pcc
int main(int argc, char** argv){
	int c;
	bool has_edit_option = false;
	bool has_pattern_file_option = false;
    bool silent = false;
	int count_option_num = 0;//count number of arguments

	int max_error = 0;//maximum edit distance allowed
	string pat_file;
	vector<string> patterns;
	vector<string> textfiles;


  	while (1){
        static struct option long_options[] =
		{
            {"silent",   no_argument,       0, 's'},
            {"help",     no_argument,       0, 'h'},
            {"edit",     required_argument, 0, 'e'},
            {"pattern",  required_argument, 0, 'p'},
            {0, 0, 0, 0}
        };
        int option_index = 0;

        c = getopt_long (argc, argv, "she:p:",long_options, &option_index);

        if (c == -1)//end
        	break;

        switch (c){
        	case 'e':
        		has_edit_option = true;
        		max_error = atoi(optarg);
        		count_option_num += 2;
        		break;
        	case 'p':
        		has_pattern_file_option = true;
        		pat_file = optarg;
        		count_option_num += 2;
        		break;
            case 's':
                silent = true;
                break;
        	case 'h':
        	case '?':
        	default:
        		help();
        		break;
        }
    }
    if(!has_pattern_file_option){//read pattern from command line arg
    	count_option_num++;
    	string pat(argv[count_option_num]);
		patterns.push_back(pat);
    }else{//read patterns from file
    	ifstream infile(pat_file);

		if (!infile.good()){
			cout << "Arquivo de padrão << " << pat_file << " >> não existe" << endl;
		}

		string pat;
		while (infile >> pat){
			patterns.push_back(pat);
		}
    }

    if(argc - 1 <= count_option_num){
    	cout << "Insira 1 ou mais arquivos de texto" << endl;
    }

    for (int i = count_option_num+1; i < argc; i++){
		string str = argv[i];
		vector<string> files = getTextFiles(str);
		for(string &file : files){
			textfiles.push_back(file);
		}
	}

	if(!has_edit_option || max_error == 0){//exact search
		if(patterns.size() == 1){//kmp
			string pat = patterns[0];
			for(string &txt : textfiles){
				run_kmp(txt, pat, silent);
			}
		}else if(patterns.size() > 1){//aho
			for(string &txt : textfiles){
				run_aho(txt, patterns, silent);
			}
		}else{
			//error
		}
	}else if(has_edit_option){//approximate search
		for(string &txt : textfiles){
			for(string &pat : patterns){
                if(pat.length() < 64){
                    run_wu_manber(txt, pat, max_error, silent);
                }else{
				    run_sellers(txt, pat, max_error, silent);
                }
			}
		}
	}
	
	return 0;
}