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

暴力1A。。。

Posted by iluoer at 2016-10-28 13:55:42 on Problem 1035
#include <cstdio>
#include <string.h>

const int maxn = 1e4+10;
struct node{
    char d[55];
    int len;
}c[maxn];

char k[55];

int main()
{
    int n = 0;
    while(~scanf("%s",c[n].d) && c[n].d[0]!='#'){
        c[n].len = strlen(c[n].d);
        n++;
    }
    while(~scanf("%s",k) && k[0]!='#'){
        int ans = 0;
        bool zq = false;
        for(int i=0;i<n;i++){
            ans = 0;
            if(c[i].len == strlen(k)){
                for(int j=0;j<c[i].len;j++){
                    if(k[j]==c[i].d[j]){
                        ans++;
                    }
                }
                if(ans == c[i].len){zq = true;break;}
            }
        }
        if(!zq){
            printf("%s:",k);
            for(int i=0;i<n;i++){
                if(c[i].len == strlen(k)+1){
                    int p=0,j=0;
                    for(;j<c[i].len;){
                        if(k[p]!=c[i].d[j]){
                            j++;
                        }else{
                            j++;
                            p++;
                        }
                    }
                    if(p == strlen(k)) printf(" %s",c[i].d);
                }
                if(c[i].len == strlen(k)-1){
                    int p=0,j=0;
                    for(;j<c[i].len+1;){
                        if(k[p]!=c[i].d[j]){
                            p++;
                        }else{
                            j++;
                            p++;
                        }
                    }
                    if(p-1 == strlen(k)) printf(" %s",c[i].d);
                }
                if(c[i].len == strlen(k)){
                    int j=0,ans = 0;
                    for(;j<c[i].len+1;j++){
                        if(k[j]!=c[i].d[j]){
                            ans++;
                        }
                    }
                    if(ans == 1) printf(" %s",c[i].d);
                }
            }
        }else{
            printf("%s is correct",k);
        }
        printf("\n");
    }
    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