?一、字符串平均重量
?
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
double total;
int strNum=0;
string str;
while(cin>>str){
strNum++;
total+=str.size();
}
printf("%.2f",total/strNum);
return 0;
}
二、solo习惯
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
string str;
getline(cin,str);
for(int i=0;i<str.size();i++){
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'){
str[i]=str[i]-('a'-'A');
}else if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||str[i]==' '){
continue;
}else if(str[i]>='A'&&str[i]<='Z'){
str[i]=str[i]+('a'-'A');
}
}
cout<<str<<endl;
return 0;
}
三、计算字符串重新排列数
?
?完成67%
#include<algorithm>
#include<string.h>
#include<iostream>
// we have defined the necessary header files here FOR this problem.
// IF additional header files are needed IN your program, please IMPORT here.
int main()
{
// please define the C input here. FOR EXAMPLE: int n; scanf("%d",&n);
// please finish the FUNCTION body here.
// please define the C output here. FOR EXAMPLE: printf("%d",a);
char num[9];
cin>>num;
int n = strlen(num);
int result=0;
sort(num,num+n);
do
{
//for(int i=0;i<n;i++){
// cout<<num[i]<<" ";
// cout<<endl;
//}
result++;
}while(next_permutation(num,num+n));
cout<<result<<endl;
return 0;
}
?完成97%
//#include <iostream>
//#include <cstring>
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<set>
using namespace std;
void AllPermutation(string perm, int from, int to);
int num=0;
set<string> sets;
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
string str;
getline(cin,str);
AllPermutation(str, 0, str.size()-1);
cout<<sets.size()<<endl;
return 0;
}
void AllPermutation(string perm, int from, int to)
{
if(from > to)
return;
if(from == to) //打印当前排列
{
static int count = 1; //局部静态变量,用来统计全排列的个数
num=count;
count++;
sets.insert(perm);
//cout << count++ << ":" << perm;
//cout << endl;
}
if(from < to) //用递归实现全排列
{
for(int j = from; j <= to; j++) //第j个字符分别与它后面的字符交换就能得到新的排列
{
swap(perm[j], perm[from]);
//cout<<0;
AllPermutation(perm, from + 1, to);
//cout<<1;
swap(perm[j], perm[from]);
//cout<<2;
}
}
}
100%?
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
string str;
int count=0;
getline(cin,str);
//没有sort好像不行
sort(str.begin(),str.end());
do{
//cout<<str<<endl;
count++;
}while(next_permutation(str.begin(),str.end()));
cout<<count<<endl;
return 0;
}
|