HDU 2708 Vertical Histogram

Description

输入4行字符串,然后按题意输出

Algorithm

模拟

Hint

又是多组数据不告诉
然后就是要删除空行 和 行末字符

Code

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string s;
  while (getline(cin, s))
  {
    int a[26] = {0};
    int maxn = 0;
    for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < s.size(); j++)
        if (s[j] >= 'A' && s[j] <= 'Z')
        {
          a[s[j] - 'A']++;
          if (a[s[j] - 'A'] > maxn)  maxn = a[s[j] - 'A'];
        }
      getline(cin, s);
    }
    for (int j = 0; j < s.size(); j++)
      if (s[j] >= 'A' && s[j] <= 'Z')
      {
        a[s[j] - 'A']++;
        if (a[s[j] - 'A'] > maxn)  maxn = a[s[j] - 'A'];
      }
    for (int i = 0; i < maxn; i++)
    {
      string ans;
      for (int j = 0; j < 26; j++)
        if (a[j] >= maxn - i) ans += "* "; else ans += " ";
      int l = ans.size() - 1;
      while (ans[l] == ' ')
      {
        ans.erase(l, 1);
        l--;
    }
    if (!ans.empty())
    {
      cout << ans << endl;
    }
  }
  for (int i = 0; i < 25; i++)
    cout << (char)(i + 'A') << ' ';
  cout << 'Z' << endl;
  }
}

你可能感兴趣的:(HDU 2708 Vertical Histogram)