标记数字:
#include <iostream>
#include <string>
using namespace std;
const string mark="*";
bool check_num(char c)
{
if(c>47&&c<58)
{
return true;
}
else
{
return false;
}
}
void mark_num(string& in_str)
{
int tag=0;
size_t size=in_str.length();
for(size_t i=0; i<size; ++i)
{
if(check_num(in_str[i]))
{
++tag;
}
else
{
if(tag!=0)
{
in_str.insert(i-tag,mark);
in_str.insert(i+1,mark);
tag=0;
size=in_str.length();
}
}
}
if(tag!=0)
{
in_str.insert(size-tag,mark);
in_str.insert(size+1,mark);
}
}
int main()
{
string str ;
getline(cin,str);
mark_num(str);
cout << str << endl;
return 0;
}
最后单词长度:
#include <iostream>
#include <string>
using namespace std;
bool check_alpha(char c)
{
if((c>96 && c<123) || (c>64 && c<91))
{
return true;
}else
{
return false;
}
}
int last_word_length(string& in_words)
{
int tag=0;
int i=in_words.length()-1;
while(i>-1)
{
if(check_alpha(in_words[i]))
{
++tag;
}else
{
if(tag!=0)
return tag;
}
--i;
}
return tag;
}
int main()
{
string str;
getline(cin,str);
cout << last_word_length(str)<< endl;
return 0;
}
小球5次落地旅途长度:
#include <iostream>
using namespace std;
int power(int a,int b)
{
int re=a;
for(int i=1;i<b;++i)
{
re=re*a;
}
return re;
}
double get_journey(int high)
{
if(high>0)
{
double length=high;
double all=high;
for(int i=1; i<5; ++i)
{
all+=2*length/power(2,i);
}
return all;
}
else if(high==0)
{
return 0;
}
else
{
return -1;
}
}
double get_tenth_high(int high)
{
if(high>0)
{
double length=high;
return length/power(2,5);
}
else if(high==0)
{
return 0;
}
else
{
return -1;
}
}
int main()
{
int high=0;
cin>>high;
cout << get_journey(high) << endl;
cout << get_tenth_high(high) << endl;
return 0;
}