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

sample和discuss里数据都通过了但WA,求大神!方法挺简单暴力的

Posted by SGDQ111 at 2015-11-03 16:40:26 on Problem 1035
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool ifRevise(string dicstr, string sample);
int main(){
    vector<string> dict;
    string tmp;
    cin >> tmp;
	while(tmp != "#"){
		dict.push_back(tmp);
		cin >> tmp;
    }
	cin >> tmp;
    while(tmp != "#"){
        vector<string>::iterator iter;
        for(iter = dict.begin(); iter != dict.end(); ++iter){ 
			if(tmp == *iter){
				cout << tmp << " is correct" << endl;
				cin >> tmp;
				break;
            }
        }
        cout << tmp << ":";
        for(iter = dict.begin(); iter != dict.end(); ++iter){
			if(ifRevise(*iter, tmp)){ 
				cout << " "<< *iter; 
            }
        }
        cout << endl;
		cin >> tmp;
	}
	return 0;
}
bool ifRevise(string dicstr, string sample){
    int ErrorCase;
	if(dicstr.length() == sample.length() + 1){
		ErrorCase = 1;
	}else if(dicstr.length() == sample.length()){
		ErrorCase = 2;
	}else if(dicstr.length() == sample.length() - 1){
		ErrorCase = 3;
	}else{
		return false;
	}
    int count = 0, j = 0;
    for(int i = 0; i < dicstr.length(); i++){
	if(j == sample.length() && ErrorCase == 1 && count == 0)          
            return true;
        if(dicstr[i] == sample[j++]){
            continue;
        }else if(count == 0){
			switch(ErrorCase){
			case 1: j--; break;
			case 2: break;
			case 3: i--; break;
			}
            count = 1;
        }else if(count == 1){
			return false;
        }
    }
    return true;
}

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