求助,这题为啥WA呀
查看原帖
求助,这题为啥WA呀
609811
accccccc楼主2022/6/14 20:36
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N = 1e7*2+10;
/*
*/
bool check(string s, char x) {
	int l = 0, r = s.size() - 1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(x == s[mid])
			return true;
		else if(x < s[mid])
			r = mid-1;
		else 
			l = mid+1;
	}
	return false;
}
bool check2(string s, char x) {
	for(int i = 0; i < s.size(); ++i) {
		if(x == s[i])
			return true;
	}
	return false;
}
int main() {
	ios::sync_with_stdio(false);  cin.tie(0);

	int round = 1; 
	while(1) {
		int id;
		string cpt, guess;
		cin >> id;
		if(id == -1)
			break;
		cin >> cpt >> guess;
		cout << "Round " << round << endl;
		set<char> st;
		for(int i = 0; i < cpt.size(); ++i) {
			st.insert(cpt[i]); //cehs
		}
		string tmp;
		int len = 0;
		set<char>::iterator it = st.begin();
		for(; it != st.end(); ++it) {
			tmp += (*it);
		}
//		cout << tmp << endl;
//		sort(guess.begin(), guess.end());
		int rec[30] = {0}, wrongNum = 0;
		set<char> st2;
		for(int i = 0; i < guess.size(); ++i) {
			if(check(tmp, guess[i])) {
//				cout << rec[guess[i] - 'a'] << endl;
				if(rec[guess[i] - 'a'] == 0) {
					rec[guess[i] - 'a']++;
					st2.insert(guess[i]);
				} else if(rec[guess[i] - 'a'] >= 1) {
					wrongNum++;
				}
			} else {
				if(rec[guess[i] - 'a'] == 0) {
					rec[guess[i] - 'a']++;
					wrongNum++;
				} else if(rec[guess[i] - 'a'] >= 1) {
					continue;
				}
			}
		}
//		cout << wrongNum << endl;
		if(st2.size() == st.size() && st2 == st && wrongNum < 7) {
			cout << "You win." << endl;
		} else if(wrongNum < 7 && st2 != st) {
			cout << "You chickened out." << endl;
		} else {
			cout << "You lose." << endl;
		}

		round++;
	}
	return 0;
}  
2022/6/14 20:36
加载中...