[#include <iostream>
#include <algorithm>
#include <vector>
usingnamespace std;
int weight_table();
int Redundancy();
int store(int,char);
int cnt = 0;//total char
int weight[126]={0};//weight for each char
int Rweight[126]={0};
char function[126]={0};//store ascenting char
char Fstr[]={0};//store char entered
char secondF[]={0};
int Rearrange();
int cnt2 =0;
int main(){
char ch;
int ref=0;
restart: cout<<"Please enter a sentence(Put '.' at the end of sentence): ";
back: cin>>ch;
cnt++;//total charactes in a sentence.
store(cnt,ch);
if (ch != '.') goto back;
weight_table();
for(int i=0; i<=cnt; i++){
cout<<"Weight of "<<"'"<<Fstr[i]<<"'"<<" are "<<weight[i]<<'\n';
}
Redundancy();
Rearrange();
cout<<"Total characters are ="<<cnt<<"\n\n";
goto restart;
return 0;
}
int store(int cnt, char ref){
Fstr[cnt]= ref;
return 0;
}
int Redundancy(){
sort(Fstr,Fstr+cnt);//sort it before unique_copy inorder to elimate duplicated characters
char *rr = unique_copy(Fstr,Fstr+cnt,function);//unique_copy(start,end,location)
*rr=0;//truccate buffer
for (int i=1; i<=cnt;i++){
if(int(function[i])!=0){//print out characters.initially,"function[]"is fillup with 0's.
cout<<"sequent2 "<< function[i] <<'\n';//PROBLEM!:"."does not print out
}
}
cnt2 = (int) count(function,function+126,0);//cal num of '0'in function which are not occupied
cout<<"num of zero's are "<<cnt2<<'\n';
return 0;
}
int weight_table(){
for(int i=1; i<=cnt;i++){//evaluting weight of characters
for(int j=1;j<=cnt;j++){
if(int(Fstr[i])-int(Fstr[j]) == 0) weight[i] = weight[i]+1;
}
}
return 0;
}
int Rearrange(){
for (int i=1;i<=126-cnt2;i++){
for(int j=1;j<=cnt;j++)
if (int(function[i])-int(secondF[j])==0) Rweight[i]=weight[j];
}
return 0;
}
]
//i have working on it many days, but still not satisfy....
//my problem is i need to eliminate the redundant characters(run it u will see)...any 1 any suggestions? thx...
#include <iostream>
#include <algorithm>
#include <vector>
usingnamespace std;
int weight_table();
int Redundancy();
int store(int,char);
int cnt = 0;//total char
int weight[126]={0};//weight for each char
int Rweight[126]={0};
char function[126]={0};//store ascenting char
char Fstr[]={0};//store char entered
char secondF[]={0};
int Rearrange();
int cnt2 =0;
int NewWeight[256];
int main(){
char ch;
int ref=0;
restart: cout<<"Please enter a sentence(Put '.' at the end of sentence): ";
back: cin>>ch;
// cnt++;//total charactes in a sentence.
// store(cnt,ch);
NewWeight[ch]++;
if (ch != '.') goto back;
// weight_table();
for(int i=0; i<256; i++){
if(NewWeight[i]){
cout<<"Weight of "<<"'"<<(char)i<<"'"<<" are "<<NewWeight[i]<<'\n';
}
}
cnt = 0;
for(i=0; i<256; i++){
if(NewWeight[i]){
cout<<"sequent2 "<<(char)i<<'\n';
cnt++;
}
}
// Redundancy();
// Rearrange();
cout<<"Total characters are ="<<cnt<<"\n\n";
goto restart;
return 0;
}
int store(int cnt, char ref){
Fstr[cnt]= ref;
return 0;
}
int Redundancy(){
sort(Fstr,Fstr+cnt);//sort it before unique_copy inorder to elimate duplicated characters
char *rr = unique_copy(Fstr,Fstr+cnt,function);//unique_copy(start,end,location)
*rr=0;//truccate buffer
for (int i=1; i<=cnt;i++){
if(int(function[i])!=0){//print out characters.initially,"function[]"is fillup with 0's.
cout<<"sequent2 "<< function[i] <<'\n';//PROBLEM!:"."does not print out
}
}
cnt2 = (int) count(function,function+126,0);//cal num of '0'in function which are not occupied
cout<<"num of zero's are "<<cnt2<<'\n';
return 0;
}
int weight_table(){
for(int i=1; i<=cnt;i++){//evaluting weight of characters
for(int j=1;j<=cnt;j++){
if(int(Fstr[i])-int(Fstr[j]) == 0) weight[i] = weight[i]+1;
}
}
return 0;
}
int Rearrange(){
for (int i=1;i<=126-cnt2;i++){
for(int j=1;j<=cnt;j++)
if (int(function[i])-int(secondF[j])==0) Rweight[i]=weight[j];
}
return 0;
}
Great!!!.flaverli....this is very useful to me...really thanks u a lot...
u let me know more ab the C++!
u let me move more faster now....really thanks ur help...