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

总结一下容易忽略的地方,附略丑的代码

Posted by altair21 at 2014-07-23 18:16:22 on Problem 1583
1.Now和now是算一个单词的,并且以小写形式输出。
2.and..and.....and     and  这是1个单词出现四遍
3.中间只要有符号,就当做是两个单词 比如i'm 当做一个i,一个m
4.中间有数字则当做一个字符,比如head4head,是一个单词
WA了很多发,最后代码越改越长。

#include<cstring>
#include<string>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<functional>
#include<cmath>
using namespace std;
#define PI acos(-1.0)
#define MAXN 10010
#define eps 1e-7
#define INF 0x7FFFFFFF
#define ff sqrt(5.0)
typedef long long ll;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

map<string,int> mp;
string ans[500],temp;
char fh[13] = {",.;\'`\"()/:-"};
char a[500];
int main(){
    map<string,int>::iterator it;
    int i,cnt,maxm = 1,flag;
    while(scanf("%s",a)!=EOF){
        cnt = 0;
        flag = 0;
        int l = strlen(a);
        for(i=0;i<l;i++){
            if(isalpha(a[i])){
                a[i] = tolower(a[i]);
            }
        }
        while(!isalpha(a[cnt])) cnt++;
        for(i=l-1;i>=cnt;i--){
            if(!isalnum(a[i])){
                a[i] = '\0';
                l--;
            }
            else    break;
        }
        for(i=0;i<l;i++){
            if(isalnum(a[i])){
                flag = 1;
                break;
            }
        }
        if(flag==1){
            int ttt = 0;
            for(i=cnt;i<l;i++){
                if(!isalnum(a[i])){
                    a[i] = '\0';
                    temp = string(a+cnt+ttt);
                    if(mp[temp]==NULL)  mp[temp] = 1;
                    else{
                        mp[temp]++;
                        if(mp[temp]>maxm)   maxm = mp[temp];
                    }
                    while(!isalnum(a[i+1])) i++;
                    ttt=i+1;
                }
            }
            temp = string(a+cnt+ttt);
            if(mp[temp]==NULL)  mp[temp] = 1;
            else{
                mp[temp]++;
                if(mp[temp]>maxm)   maxm = mp[temp];
            }
//            cout<<temp<<endl;
        }
    }
    cnt = 0;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second==maxm){
            ans[cnt++] = it->first;
        }
    }
    sort(ans,ans+cnt);
    printf("%d occurrences\n",maxm);
    for(i=0;i<cnt;i++){
        cout<<ans[i]<<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