| ||||||||||
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 |
这题一直WA,望高手赐教#include<stdio.h> #include<iostream> #include<string> #define ARRAYMAX 2000 using namespace std; typedef struct { string longstr; }words; words stWord[ARRAYMAX]; int iWordNum; char str[55]; bool cmp(char a,char b) { if(a==b) return true; else return false; } int main() { int len1; int len2; int loc; int maxloc; int flag; iWordNum=0; while(EOF!=scanf("%s",str)) { stWord[iWordNum].longstr=str; iWordNum++; } for(int i=0;i<iWordNum;i++) { flag=0; maxloc=-1; len1=stWord[i].longstr.size(); for(int i1=0;i1<iWordNum;i1++) { if(i1==i) continue; if(stWord[i].longstr==stWord[i1].longstr) { flag++; continue; } len2=stWord[i1].longstr.size(); for(int i2=0;i2<len1;i2++) { if(i2>=len2-1) { if(stWord[i].longstr[i2]==stWord[i1].longstr[i2]) loc=i2+1; else loc=i2; break; } else if(stWord[i].longstr[i2]==stWord[i1].longstr[i2]) { loc=i2+1; continue; } else { loc=i2; break; } } if(loc>maxloc) maxloc=loc; } cout<<stWord[i].longstr; cout<<" "; if(flag==iWordNum-1) maxloc=len1; for(int x=0;x<=maxloc;x++) { cout<<stWord[i].longstr[x]; } cout<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator