Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
谁能帮忙看下这段代码错再哪里?#include <iostream> #include <string> #include <algorithm> using namespace std; int BinSearch (int length, string a[], string b) { int low = 0; int high = length; int middle = (low + high) / 2; while (middle >= low && middle <= high) { if (b < a[middle]) high = middle - 1; else if (b > a[middle]) low = middle + 1; else return middle; middle = (low + high) / 2; } return -1; } int main() { int dicWordNum; scanf("%d", &dicWordNum); string words[100000]; for (int i = 0; i < dicWordNum; i++) cin >> words[i]; sort(words, words + dicWordNum); int emailNum; scanf("%d", &emailNum); int temp = emailNum; while (temp-->0) { int emailLen = 0; string email[100000]; for (int i = 0; ; i++) { cin >> email[i]; if (email[i] == "-1") { emailLen = i; break; } } bool flag = false; int j; for (j = 0; j < emailLen; j++) { int res = BinSearch (dicWordNum, words, email[j]); if (res == -1) { if (flag == false) { printf("Email %d is not spelled correctly.\n", emailNum - temp); } flag = true; printf("%s\n", email[j]); } } if (flag == false) printf("Email %d is spelled correctly.\n", emailNum - temp); } printf("End of Output\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator