从c ++字符串到c [英] From c++ string to c

查看:76
本文介绍了从c ++字符串到c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是这个小组的新人并写了一个事实,我手头有一个

的小项目,我正在编写一个可以允许输入的程序

。任意长度文本的b,双元音的数量必须是确定的。

输出:每个双元音的频率,必须确定。


例如

稍后,我们会再次见到你


输出:1xee,1xou,1xai。


我已经写了一个但是使用了新的库字符串类型字符串,但是我想要为特定目的这样做,因此希望使用相当的

c字符串和函数来自< string.h>,

例如strcpy,....但我也是非常新的c所以我还不明白如何

i可以用这种方式转换代码,我会在这里发布代码和

请欢迎任何新想法。


#include< iostream>

#include< string>

#include< cctype>

使用名称space std;


void scanner(字符串);

bool isVowel(char);


int main( ){

字符串句子;

cout<< 输入$终止! << endl;

do {

cout<< " \ n输入输入字符串:" ;;

getline(cin,sentence);

scanner(句子);

} while (句子!=" $");

返回0;

}


void scanner(字符串s){

int stringSize = s.length();

char current,next;

int count = 0;

int aa,ae,ai,ao,au,ea,ee,ei,eo,eu,ia,ie,ii,io,iu,oa,oe,oi,oo,ou,

ua,ue,ui,uo,uu;

aa = ae = ai = ao = au = 0;

ea = ee = ei = eo = eu = 0;

ia = ie = ii = io = iu = 0;

oa = oe = oi = oo = ou = 0;

ua = ue = ui = uo = uu = 0;

while(count< stringSize){

current = s [count];

if ((count + 1)== stringSize)

休息;

next = s [count + 1];

if(isVowel(current) )&& isVowel(下)){

// a

current = tolower(current);

next = tolower(next) );

if(current ==''a''&& next =='一个)

AA ++;

,否则如果(当前==一&安培;&安培; next ==''e'')

ae ++;

else if(current ==''a''&& next ==''i'' )

ai ++;

else if(current ==''a''&& next ==''o'')

ao ++;

else if(current ==''a''&& next ==''u'')

au ++;

// e

else if(current ==''e''&& next ==''a'')

ea ++;

else if(current ==''e''&& next ==''e'')

ee ++;

else if (current ==''e''&& next ==''i'')

ei ++;

else if(current ==''e' '&& next ==''o'')

eo ++;

else if(current ==''e''&& next == ''你')

eu ++;

// i

else if(current ==''i''&& next ==''a'')

ia ++;

else if(current ==''i''&& next == 'e'')

ie ++;

else if(current ==''i''&& next ==''i'')br / >
ii ++;

else if(current ==''i''&& next ==''o'')

io ++;

else if(current ==''i''&& next ==''u'')

iu ++;

// o

else if(current ==''o''& ;& next ==''a'')

oa ++;

else if(current ==''o''&& next =='' e'')

oe ++;

else if(current ==''o''&& next ==''i'')

oi ++;

else if(current ==''o''&& next ==''o'')

oo ++;

else if(current ==''o''&& next ==''u'')

ou ++;

// u

else if(current ==''u''&& next ==''a'')

ua ++;

else if(current ==''u''&& next ==''e'')

ue ++;

else if(current ==' '你'&& next ==''我')

ui ++;

else if(current ==''''&& next ==''o'')

uo ++;

else / *(current =='''''&& next == 'u'')* /

uu ++;


count ++;

}

else {

count ++;

继续;

}

}

int totalVowels = aa + ae + ai + ao + au +

ea + ee + ei + eo + eu +

ia + ie + ii + io + iu +

oa + oe + oi + oo + ou +

ua + ue + ui + uo + uu;

if(totalVowels == 0){

cout<< 没有双元音!如果(aa> 0){

cout<< aa<<" x"<<" aa";

totalVowels - = aa;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ae> 0){

cout<< ae<" x"<<" ae";

totalVowels - = ae;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ai> 0){

cout<< ai<" x"<<" ai";

totalVowels - = ai;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ao> 0){

cout<< ao<<" x"<<" ao";

totalVowels - = ao;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(au> 0){

cout<< au<<" x"<<" au";

totalVowels - = au;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ea> 0){

cout<< ea<" x"<<" ea";

totalVowels - = ea;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ee> 0){

cout<< ee<<" x"<<" ee";

totalVowels - = ee;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ei> 0){

cout<< ei<" x"<<"" ei";

totalVowels - = ei;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(eo> 0){

cout<< eo<<" x"<<" eo";

totalVowels - = eo;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(eu> 0){

cout<< eu<" x"<<"" eu";

totalVowels - = eu;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ia> 0){

cout<< ia<<" x"<<"" ia";

totalVowels - = ia;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(即> 0){

cout<<即<<" x"<<""" ;;

totalVowels - = ie;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ii> 0){

cout<< ii<"" x"<"" ii";

totalVowels - = ii;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(io> 0){

cout<< io<<" x"<<"" io" ;;

totalVowels - = io;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(iu> 0){

cout<< iu<<" x"<<" iu";

totalVowels - = iu;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oa> 0){

cout<< oa<<" x"<<" oa";

totalVowels - = oa;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oe> 0){

cout<< oe<<" x"<<" oe";

totalVowels - = oe;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oi> 0){

cout<< oi<" x"<<" oi";

totalVowels - = oi;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oo> 0){

cout<< oo<<" x"<<" oo";

totalVowels - = oo;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ou> 0){

cout<< ou<<" x"<<" ou";

totalVowels - = ou;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ua> 0){

cout<< ua<<" x"<<" ua";

totalVowels - = ua;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ue> 0){

cout<< ue<<" x"<<" ue";

totalVowels - = ue;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ui> 0){

cout<< ui<<" x"<<" ui";

totalVowels - = ui;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(uo> 0){

cout<< uo<<" x"<<" uo";

totalVowels - = uo;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(uu> 0){

cout<< uu<<" x"<<" uu"<<"。" ;;

totalVowels - = uu;

}

}


bool isVowel(char c){

return(c ==''a''|| c = =''A''|| c ==''e''||

c ==''E''|| c ==''我''|| c ==''我'|| c ==''o''||

c ==''O''|| c ==''u''|| c ==''U'' );

}

hello , i ma new in this group and writing over the fact that i have a
small project at hand,i am writing a program which can permit the input
of a text of arbitary lenght,and the number of double vowels must be
determined.
Output:frequency of each double vowel ,must be dtermined.

e.g.
Later ,we will see you again

OUTPUT:1xee,1xou,1xai.

I already wrote one but using the new library string type string,but i
wish to do this for a particular purpose and hence wish to use rather
the c string and functions from <string.h>,
e.g strcpy,....but i am also very new in c so i have not understood how
i can convert the code in that way, i will post the code here and
please welcome any new ideas.

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

void scanner(string);
bool isVowel(char);

int main(){
string sentence;
cout << "Enter $ to terminate!" <<endl;
do{
cout << "\nEnter the input string: ";
getline(cin,sentence);
scanner(sentence);
}while(sentence != "$");
return 0;
}

void scanner(string s){
int stringSize = s.length();
char current,next;
int count = 0;
int aa,ae,ai,ao,au,ea,ee,ei,eo,eu,ia,ie,ii,io,iu,oa,oe ,oi,oo,ou,
ua,ue,ui,uo,uu;
aa = ae = ai = ao = au = 0;
ea = ee = ei = eo = eu = 0;
ia = ie = ii = io = iu = 0;
oa = oe = oi = oo = ou = 0;
ua = ue = ui = uo = uu = 0;
while(count < stringSize){
current = s[count];
if( (count + 1) == stringSize)
break;
next = s[count + 1];
if(isVowel(current) && isVowel(next)){
//a
current = tolower(current);
next = tolower(next);
if( current == ''a'' && next == ''a'')
aa++;
else if( current == ''a'' && next == ''e'')
ae++;
else if( current == ''a'' && next == ''i'')
ai++;
else if( current == ''a'' && next == ''o'')
ao++;
else if( current == ''a'' && next == ''u'')
au++;
//e
else if( current == ''e'' && next == ''a'')
ea++;
else if( current == ''e'' && next == ''e'')
ee++;
else if( current == ''e'' && next == ''i'')
ei++;
else if( current == ''e'' && next == ''o'')
eo++;
else if( current == ''e'' && next == ''u'')
eu++;
//i
else if( current == ''i'' && next == ''a'')
ia++;
else if( current == ''i'' && next == ''e'')
ie++;
else if( current == ''i'' && next == ''i'')
ii++;
else if( current == ''i'' && next == ''o'')
io++;
else if( current == ''i'' && next == ''u'')
iu++;
//o
else if( current == ''o'' && next == ''a'')
oa++;
else if( current == ''o'' && next == ''e'')
oe++;
else if( current == ''o'' && next == ''i'')
oi++;
else if( current == ''o'' && next == ''o'')
oo++;
else if( current == ''o'' && next == ''u'')
ou++;
//u
else if( current == ''u'' && next == ''a'')
ua++;
else if( current == ''u'' && next == ''e'')
ue++;
else if( current == ''u'' && next == ''i'')
ui++;
else if( current == ''u'' && next == ''o'')
uo++;
else /*( current == ''u'' && next == ''u'')*/
uu++;

count++;
}
else{
count++;
continue;
}
}
int totalVowels = aa + ae + ai + ao + au +
ea + ee + ei + eo + eu +
ia + ie + ii + io + iu +
oa + oe + oi + oo + ou +
ua + ue + ui + uo + uu ;
if(totalVowels == 0){
cout << "No double vowels!" <<endl;
}
if(aa > 0){
cout << aa <<"x "<<"aa";
totalVowels -= aa;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ae > 0){
cout << ae <<"x "<<"ae";
totalVowels -= ae;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ai > 0){
cout << ai <<"x "<<"ai";
totalVowels -= ai;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ao > 0){
cout << ao <<"x "<<"ao";
totalVowels -= ao;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(au > 0){
cout << au <<"x "<<"au";
totalVowels -= au;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ea > 0){
cout << ea <<"x "<<"ea";
totalVowels -= ea;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ee > 0){
cout << ee <<"x "<<"ee";
totalVowels -= ee;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ei > 0){
cout << ei <<"x "<<"ei";
totalVowels -= ei;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(eo > 0){
cout << eo <<"x "<<"eo";
totalVowels -= eo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(eu > 0){
cout << eu <<"x "<<"eu";
totalVowels -= eu;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ia > 0){
cout << ia <<"x "<<"ia";
totalVowels -= ia;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ie > 0){
cout << ie <<"x "<<"ie";
totalVowels -= ie;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ii > 0){
cout << ii <<"x "<<"ii";
totalVowels -= ii;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(io > 0){
cout << io <<"x "<<"io";
totalVowels -= io;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(iu > 0){
cout << iu <<"x "<<"iu";
totalVowels -= iu;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oa > 0){
cout << oa <<"x "<<"oa";
totalVowels -= oa;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oe > 0){
cout << oe <<"x "<<"oe";
totalVowels -= oe;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oi > 0){
cout << oi <<"x "<<"oi";
totalVowels -= oi;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oo > 0){
cout << oo <<"x "<<"oo";
totalVowels -= oo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ou > 0){
cout << ou <<"x "<<"ou";
totalVowels -= ou;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ua > 0){
cout << ua <<"x "<<"ua";
totalVowels -= ua;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ue > 0){
cout << ue <<"x "<<"ue";
totalVowels -= ue;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ui > 0){
cout << ui <<"x "<<"ui";
totalVowels -= ui;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(uo > 0){
cout << uo <<"x "<<"uo";
totalVowels -= uo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(uu > 0){
cout << uu <<"x "<<"uu"<<".";
totalVowels -=uu;
}
}

bool isVowel(char c){
return (c == ''a'' || c == ''A'' || c == ''e'' ||
c == ''E'' || c == ''i'' || c == ''I'' || c == ''o'' ||
c == ''O'' || c == ''u'' || c == ''U'') ;
}

推荐答案

终止! << endl;

do {

cout<< " \ n输入输入字符串:" ;;

getline(cin,sentence);

scanner(句子);

} while (句子!="
to terminate!" <<endl;
do{
cout << "\nEnter the input string: ";
getline(cin,sentence);
scanner(sentence);
}while(sentence != "


");

返回0;

}


void scanner(字符串s){

int stringSize = s.length();

char current,next;

int count = 0;

int aa,ae,ai,ao,au,ea,ee,ei,eo,eu,ia,ie,ii,io,iu,oa,oe,oi,oo, ou,

ua,ue,ui,uo,uu;

aa = ae = ai = ao = au = 0;

ea = ee = ei = eo = eu = 0;

ia = ie = ii = io = iu = 0;

oa = oe = oi = oo = ou = 0;

ua = ue = ui = uo = uu = 0;

while(count< stringSize){

current = s [count] ;

if((count + 1)== stringSize)

break;

next = s [count + 1];

if(isVowel(current)&& isVowel(next)){

// a

current = tolower(current);

next = tolower(next);

if(current ==''a &安培;&安培; next ==''a'')

aa ++;

else if(current ==''a''&& next ==''e'' )

ae ++;

else if(current ==''a''&& next ==''i'')

ai ++;

else if(current ==''a''&& next ==''o'')

ao ++;

else if(current ==''a''&& next ==''u'')

au ++;

// e

else if(current ==''e''&& next ==''a'')

ea ++;

else if (current ==''e''&& next ==''e'')

ee ++;

else if(current ==''e' '&& next ==''我')

ei ++;

else if(current ==''e''&& next == ''o'')

eo ++;

else if(current ==''e''&& next ==''u'')br />
eu ++;

// i

else if(current ==''i''&& next == 'a'')

ia ++;

else if(current ==''i''&& next ==''e'')

ie ++;

else if(current ==''i''&& next ==''i'')

ii ++;

else if(current ==''i''&& next ==''o'')

io ++;

else if(current ==''i''&& next ==''u'' )

iu ++;

// o

else if(current ==''o''&& next =='' a'')

oa ++;

else if(current ==''o''&& next ==''e'')

oe ++;

else if(current ==''o''&& next ==''i'')

oi ++;

else if(current ==''o''&& next ==''o'')

oo ++;

else if (current ==''o''&& next ==''u'')

ou ++;

// u

else if(current ==''u''&& next ==''a'')

ua ++;

else if(current ==' 'u''&& next ==''e'')

ue ++;

else if(current ==''''&&& next ==''i'')

ui ++;

else if(current ==''''&& next == 'o'')

uo ++;

else / *(current ==''u''&& next ==''u'')* /

uu ++;


count ++;

}

else {

count ++;

继续;

}

}

int totalVowels = aa + ae + ai + ao + au +

ea + ee + ei + eo + eu +

ia + ie + ii + io + iu +

oa + oe + oi + oo + ou +

ua + ue + ui + uo + uu;

if(totalVowels == 0){

cout< ;< 没有双元音!如果(aa> 0){

cout<< aa<<" x"<<" aa";

totalVowels - = aa;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ae> 0){

cout<< ae<" x"<<" ae";

totalVowels - = ae;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ai> 0){

cout<< ai<" x"<<" ai";

totalVowels - = ai;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ao> 0){

cout<< ao<<" x"<<" ao";

totalVowels - = ao;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(au> 0){

cout<< au<<" x"<<" au";

totalVowels - = au;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ea> 0){

cout<< ea<" x"<<" ea";

totalVowels - = ea;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ee> 0){

cout<< ee<<" x"<<" ee";

totalVowels - = ee;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ei> 0){

cout<< ei<" x"<<"" ei";

totalVowels - = ei;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(eo> 0){

cout<< eo<<" x"<<" eo";

totalVowels - = eo;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(eu> 0){

cout<< eu<" x"<<"" eu";

totalVowels - = eu;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ia> 0){

cout<< ia<<" x"<<"" ia";

totalVowels - = ia;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(即> 0){

cout<<即<<" x"<<""" ;;

totalVowels - = ie;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ii> 0){

cout<< ii<"" x"<"" ii";

totalVowels - = ii;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(io> 0){

cout<< io<<" x"<<"" io" ;;

totalVowels - = io;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(iu> 0){

cout<< iu<<" x"<<" iu";

totalVowels - = iu;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oa> 0){

cout<< oa<<" x"<<" oa";

totalVowels - = oa;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oe> 0){

cout<< oe<<" x"<<" oe";

totalVowels - = oe;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oi> 0){

cout<< oi<" x"<<" oi";

totalVowels - = oi;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(oo> 0){

cout<< oo<<" x"<<" oo";

totalVowels - = oo;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ou> 0){

cout<< ou<<" x"<<" ou";

totalVowels - = ou;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ua> 0){

cout<< ua<<" x"<<" ua";

totalVowels - = ua;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ue> 0){

cout<< ue<<" x"<<" ue";

totalVowels - = ue;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(ui> 0){

cout<< ui<<" x"<<" ui";

totalVowels - = ui;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(uo> 0){

cout<< uo<<" x"<<" uo";

totalVowels - = uo;

if(totalVowels == 0)

cout<<"。" ;;

else cout<<"," ;;

}

if(uu> 0){

cout<< uu<<" x"<<" uu"<<"。" ;;

totalVowels - = uu;

}

}


bool isVowel(char c){

return(c ==''a''|| c = =''A''|| c ==''e''||

c ==''E''|| c ==''我''|| c ==''我'|| c ==''o''||

c ==''O''|| c ==''u''|| c ==''U'' );

}

");
return 0;
}

void scanner(string s){
int stringSize = s.length();
char current,next;
int count = 0;
int aa,ae,ai,ao,au,ea,ee,ei,eo,eu,ia,ie,ii,io,iu,oa,oe ,oi,oo,ou,
ua,ue,ui,uo,uu;
aa = ae = ai = ao = au = 0;
ea = ee = ei = eo = eu = 0;
ia = ie = ii = io = iu = 0;
oa = oe = oi = oo = ou = 0;
ua = ue = ui = uo = uu = 0;
while(count < stringSize){
current = s[count];
if( (count + 1) == stringSize)
break;
next = s[count + 1];
if(isVowel(current) && isVowel(next)){
//a
current = tolower(current);
next = tolower(next);
if( current == ''a'' && next == ''a'')
aa++;
else if( current == ''a'' && next == ''e'')
ae++;
else if( current == ''a'' && next == ''i'')
ai++;
else if( current == ''a'' && next == ''o'')
ao++;
else if( current == ''a'' && next == ''u'')
au++;
//e
else if( current == ''e'' && next == ''a'')
ea++;
else if( current == ''e'' && next == ''e'')
ee++;
else if( current == ''e'' && next == ''i'')
ei++;
else if( current == ''e'' && next == ''o'')
eo++;
else if( current == ''e'' && next == ''u'')
eu++;
//i
else if( current == ''i'' && next == ''a'')
ia++;
else if( current == ''i'' && next == ''e'')
ie++;
else if( current == ''i'' && next == ''i'')
ii++;
else if( current == ''i'' && next == ''o'')
io++;
else if( current == ''i'' && next == ''u'')
iu++;
//o
else if( current == ''o'' && next == ''a'')
oa++;
else if( current == ''o'' && next == ''e'')
oe++;
else if( current == ''o'' && next == ''i'')
oi++;
else if( current == ''o'' && next == ''o'')
oo++;
else if( current == ''o'' && next == ''u'')
ou++;
//u
else if( current == ''u'' && next == ''a'')
ua++;
else if( current == ''u'' && next == ''e'')
ue++;
else if( current == ''u'' && next == ''i'')
ui++;
else if( current == ''u'' && next == ''o'')
uo++;
else /*( current == ''u'' && next == ''u'')*/
uu++;

count++;
}
else{
count++;
continue;
}
}
int totalVowels = aa + ae + ai + ao + au +
ea + ee + ei + eo + eu +
ia + ie + ii + io + iu +
oa + oe + oi + oo + ou +
ua + ue + ui + uo + uu ;
if(totalVowels == 0){
cout << "No double vowels!" <<endl;
}
if(aa > 0){
cout << aa <<"x "<<"aa";
totalVowels -= aa;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ae > 0){
cout << ae <<"x "<<"ae";
totalVowels -= ae;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ai > 0){
cout << ai <<"x "<<"ai";
totalVowels -= ai;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ao > 0){
cout << ao <<"x "<<"ao";
totalVowels -= ao;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(au > 0){
cout << au <<"x "<<"au";
totalVowels -= au;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ea > 0){
cout << ea <<"x "<<"ea";
totalVowels -= ea;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ee > 0){
cout << ee <<"x "<<"ee";
totalVowels -= ee;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ei > 0){
cout << ei <<"x "<<"ei";
totalVowels -= ei;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(eo > 0){
cout << eo <<"x "<<"eo";
totalVowels -= eo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(eu > 0){
cout << eu <<"x "<<"eu";
totalVowels -= eu;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ia > 0){
cout << ia <<"x "<<"ia";
totalVowels -= ia;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ie > 0){
cout << ie <<"x "<<"ie";
totalVowels -= ie;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ii > 0){
cout << ii <<"x "<<"ii";
totalVowels -= ii;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(io > 0){
cout << io <<"x "<<"io";
totalVowels -= io;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(iu > 0){
cout << iu <<"x "<<"iu";
totalVowels -= iu;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oa > 0){
cout << oa <<"x "<<"oa";
totalVowels -= oa;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oe > 0){
cout << oe <<"x "<<"oe";
totalVowels -= oe;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oi > 0){
cout << oi <<"x "<<"oi";
totalVowels -= oi;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oo > 0){
cout << oo <<"x "<<"oo";
totalVowels -= oo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ou > 0){
cout << ou <<"x "<<"ou";
totalVowels -= ou;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ua > 0){
cout << ua <<"x "<<"ua";
totalVowels -= ua;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ue > 0){
cout << ue <<"x "<<"ue";
totalVowels -= ue;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ui > 0){
cout << ui <<"x "<<"ui";
totalVowels -= ui;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(uo > 0){
cout << uo <<"x "<<"uo";
totalVowels -= uo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(uu > 0){
cout << uu <<"x "<<"uu"<<".";
totalVowels -=uu;
}
}

bool isVowel(char c){
return (c == ''a'' || c == ''A'' || c == ''e'' ||
c == ''E'' || c == ''i'' || c == ''I'' || c == ''o'' ||
c == ''O'' || c == ''u'' || c == ''U'') ;
}


" Prof.Stanley"写道:
"Prof.Stanley" writes:
你好,我是这个小组的新人并写了一个事实,我手边有一个小项目,我正在编写一个程序,可以允许输入
一个任意长度的文本,必须确定双元音的数量。
输出:每个双元音的频率,必须确定。
hello , i ma new in this group and writing over the fact that i have a
small project at hand,i am writing a program which can permit the input
of a text of arbitary lenght,and the number of double vowels must be
determined.
Output:frequency of each double vowel ,must be dtermined.



< snip>


这对您的问题没有真正的回应,但您是否知道状态

机器?我的直觉是以某种方式实现状态机来解决这个问题,我怀疑代码会更简单。


<snip>

This is not really responsive to your question but are you aware of state
machines? My instincts would be to implement a state machine somehow in
solving this problem, I suspect the code would be much simpler.


这篇关于从c ++字符串到c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆