1011 - 空心六边形
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n - i; j++)
{
cout << " ";
}
if (i == 1)
{
for (j = 1; j <= n; j++)
{
cout << "*";
}
}
else
{
cout << "*";
for (j = 1; j <= n + 2 * (i - 2); j++)
{
cout << " ";
}
cout << "*";
}
cout << endl;
}
for (i = n - 1; i >= 1; i--)
{
for (j = 1; j <= n - i; j++)
{
cout << " ";
}
if (i == 1)
{
for (j = 1; j <= n; j++)
{
cout << "*";
}
}
else
{
cout << "*";
for (j = 1; j <= n + 2 * (i - 2); j++)
{
cout << " ";
}
cout << "*";
}
cout << endl;
}
return 0;
}
1012 - 我是第几个单词
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str1,str2;
int num1 = 0,word_number = 1,nearest = 9999,num2 = 0;
getline(cin,str1);
getline(cin,str2);
str2=" " +str2 ;
int a=str1.find(str2);
if (a>=0)
{
for(int i=0;i<str1.size();i++)
{
if(str1[i]==' ')
{
num2++;
if (abs(i-a)<nearest)
{
nearest=abs(i-a);
if (nearest==0) break;
}
}
}
cout<<num2+1;
}
else if(a<0)
{
for (int i=0;i<str1.size();i++)
if ((str1[i]>64&&str1[i]<91)||(str1[i]>96&&str1[i]<123)) num1++;
cout<<num1;
}
return 0;
}
1013 - 一个六位数
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout<<"179487";
return 0;
}
1014 - 编程求1+1/2+1/3+...+1/n
#include<bits/stdc++.h>
using namespace std;
int main()
{
float n,sum=1;
cin>>n;
for(int i=2;i<=n;i++)
{
sum+=1.0/i;
}
printf("%.3lf",sum);
return 0;
}
1015 - 鸡兔同笼问题
#include <bits/stdc++.h>
using namespace std;
int main(){
for(int i=0;i<=50;i++)
{
if(i*4+(50-i)*2==160)
{
cout<<50-i<<" "<<i<<endl;
}
}
return 0;
}