#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int vovles_count[5] = { 0,0,0,0,0 };
char vovwls[5] = { 'a','e','i','o','u' };
char vov;
int nonVov = 0 , punt = 0 , douseq = 0;
//std::cin >> std::noskipws; //tells not to skip white spaces
while (cin >> vov)
{
switch (vov)
{
case 'a':
++vovles_count[0];
break;
case 'e':
++vovles_count[1];
break;
case 'i':
++vovles_count[2];
break;
case 'o':
++vovles_count[3];
break;
case 'u':
++vovles_count[4];
break;
case ' ':
++punt;
break;
case '\n':
++punt;
break;
case 'f':
cin >> vov;
if (vov == 'l' || vov == 'f')
{
++douseq;
++nonVov; //previous f
++nonVov; //current f
}
else if (vov == 'i')
{
++vovles_count[2];
++douseq;
++nonVov; //previous f
}
else if (vov == ' ' || vov == '\n')
++punt;
break;
default:
++nonVov;
break;
}
}
for (int i = 0; i < 5; ++i)
{
cout << vovwls[i] << " occured for " << vovles_count[i] << "times" << '\n';
}
cout << '\n' << nonVov << " are the occurence of non vovels " << '\n' ;
cout << '\n' << punt << " are the occurence of whitespaces " << '\n';
cout << '\n' << douseq << " are the occurence of double sequence " << '\n';
system("pause");
return 0;
}
我不认为我在代码中看到任何问题,但我不知道为什么没有读取空格?
答案 0 :(得分:0)
使用cin默认会跳过空格。你可以尝试其他方式:
这个函数的代码重载对你有帮助:
istream& get (char* s, streamsize n, char delim);
将'\ n'放在delim中以在输入
时结束输入行