Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

恳求各位大神看看我的代码或者给些测试用例,我快崩溃了,一直wa。自己试的都没问题。

Posted by xllsniper at 2015-01-29 22:07:19 on Problem 1226
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	freopen ( "data.txt" , "r" , stdin);
	
	int team ;//组数
	int row ;//每组字符串数目
	int i , j , k , m ;
	string data [100] ;
	
	cin >> team ; 
	
	for ( i = 0 ; i < team ; i ++ ){
		cin >> row ;
		
		int lessLen ; //最短字符串长度
		int lessNum ;//最短字符串编号
		string temp , retemp ; //可能匹配的字符串、逆序字符串

		//输入每组字符串
		for ( j = 0 ; j < row ; j ++ ){
			cin >> data [ j ] ;
		}

		//求最短字符串长度、最短字符串编号
		lessLen = data[0].length();//初始时默认第一个字符串为最短字符串
		lessNum = 0;
		for ( j = 1 ; j < row ; j ++ ){
			if ( data[j].length() < lessLen){
				lessLen = data[j].length();
				lessNum = j ;
			}
		}
		
		//每组字符串进行处理,求出最短字符串的每个子串,分别判断与别的字符串的符合情况。

		k = 0 ; 
		m = lessLen ; 

		for ( j = 0 ; j < row ; j ++ ){

			while ( m > 0 ) {
				temp = data[lessNum].substr( k , m ) ; //substr第一个参数为开始序号,第二个为字符数.
				retemp = temp ; 
				reverse ( retemp.begin() , retemp.end() );

				if ( data[j].find ( temp ) != temp.npos  || data[j].find ( retemp ) != retemp.npos ) { //找到
					break;
				}
				else {
					if ( k + m < lessLen ){
						k ++ ;
					}
					else {
						k = 0 ; 
						m -- ;
						
					}
				}
				
			}
			
		}
					
		if ( m == 0 ){
			cout << 0 << endl ;
		}
		else {
			cout << temp.length() << endl ;
		}
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator