马上天梯了 这几天做一下以前的题目 听学长说一个人低于90分整队没成绩 虽然学长说题目很水但还是有点害怕...
题意:输入一个n和c 表示最多用到n个c字符 输出沙漏的形状和未用完的字符个数
易错点:字符后面没有空格。。。因为在字符后面补了空格一直wa 很水的一个题 本来不想写 就当水一篇博客吧。。毫无营养
思路:第i层需要2*i-1个c字符
对于上半层来说 每层需要j个空格 和 2*(cnt-i)+1个c字符
对于下半层来说 每层需要cnt-i个空格 和 2*i-1个c字符
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
using namespace std;
const int INF = 0x3f3f3f3f;//?????
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pll;
typedef pair<int, int> pii;
const int N = 1000000;
int a[55],b[55],prime[N],st[N];ll sum[N];
int cnt;
ll qpow(ll x,ll y,ll mod)
{
int ans=1;
while(y)
{
if(y&1) ans=ans*x%mod;
x=x*x%mod;
y>>=1;
}
return ans%mod;
}
void ola()
{
for(int i=2;i<=1000000;i++)
{
if(st[i]==0)
{
prime[cnt++]=i;
}
for(int j=0;j<cnt&&i*prime[j]<=1000000;j++)
{
st[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
int main()
{
IOS;
int n; cin >> n; char c; cin >> c;
int cnt=1;//层数
int sum=1;//符号总数
while(sum<=n)
{
cnt++;
sum+=2*(2*cnt-1);
}
sum-=2*(2*cnt-1);
cnt--;
for(int i=1;i<=cnt;i++)
{
for(int j=1;j<i;j++)
{
cout << " ";
}
for(int k=1;k<=2*(cnt-i)+1;k++)
{
cout << c;
}
cout << endl;
}
for(int i=2;i<=cnt;i++)
{
for(int j=1;j<=(cnt-i);j++)
{i
cout << " ";
}
for(int k=1;k<=2*i-1;k++)
{
cout << c;
}
cout << endl;
}
cout << n-sum << endl;
return 0;
} 
京公网安备 11010502036488号