Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // String_sequential.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <ctime>
- #include <string>
- using namespace std;
- int main(){
- FILE * file;
- file = fopen("input_big.txt", "r");
- // file = fopen("input_stupid.txt", "r");
- // file = fopen("input_no_ans.txt", "r");
- int n;
- fscanf(file, "%d", &n);
- vector<string> v(n);
- for (int i = 0; i < n; ++i) {
- char tmp[10000];
- fscanf(file, "%s", &tmp);
- v[i] = string(tmp);
- }
- fclose(file);
- long long start = clock();
- int ans = 1e7;
- for (int i = 0; i < n; ++i) {
- int cur = 0;
- for (int j = 0; j < n; ++j) {
- string tmp = v[j] + v[j];
- size_t p = tmp.find(v[i]);
- if (p == string::npos) {
- ans = -1;
- }
- else
- {
- cur += p;
- }
- }
- ans = min(ans, cur);
- }
- cout << ans << endl;
- long long end = clock();
- cout << (double)(end - start) / CLOCKS_PER_SEC << " sec " << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement