| ||||||||||
| 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 | |||||||||
1885 why can't i pass.........puzzling.#include<iostream>
#include<string>
using namespace std;
int change(int k,int j);
bool isalpha(char ch);
int pow(int base,int x);
void check(int num,int pos1,int pos2);
string a;
int lenOfTemp;
int lenOfNum;
int main(){
getline(cin,a,'0');
int num;
int i,j,k;
for (i=0;i<a.length();i++){
if (isdigit(a[i])){
j=i;
k=i;
while (isdigit(a[j])){
j++;
}
num=change(k,j);
check(num,i,j-1);
i=i+lenOfTemp-1;
}
}
cout<<a;
return 0;
}
bool isalpha(char ch){
if ((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
return true;
else return false;
}
int pow(int base,int x){
int temp=1;
for (int i=0;i<x;i++)
temp=temp*10;
return temp;
}
int change(int k,int j){
int b[10];
int i=j-k-1;
int temp=k;
while(temp<j){
b[i]=a[temp]-'0';
temp++;
i--;
}
int total=0;
for (i=0;i<j-k;i++)
total+=b[i]*pow(10,i);
return total;
}
void check(int num,int pos1,int pos2){
string b[10000];
int count=-1;
int j=pos1;
int k;
string temp;
bool ok;
while(num>0){
ok=true;
while(!isalpha(a[j]))//not alpha
j--;
k=j;
while(isalpha(a[k]))
k--;
temp=a.substr(k+1,j-k);
for (int m=0;m<=count;m++){
if (temp==b[m]){
ok=false;
break;
}
}
if (ok){
num--;
count++;
b[count]=temp;
j=k;
}
else j=k;
}
string c=a.substr(0,pos1)+temp+a.substr(pos2+1,a.length()-pos2-1 );
a=c;
lenOfTemp=temp.length();
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator