Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A,用的goto语句。。。(附代码)

Posted by cxlm at 2018-01-28 13:05:40 on Problem 1575
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    char inp[25];
    int len,flag=0,i;
    int con_v=0,con_c=0;
    cin>>inp;
    while(strcmp(inp,"end")!=0){

        /*It must contain at least one vowel.*/

        for(len=0;inp[len]!='\0';len++){//获取字符串总长度并判断是否包含元音
            if(inp[len]=='a'||inp[len]=='e'||inp[len]=='i'||inp[len]=='o'||inp[len]=='u'){
                flag=1;
            }
        }

        if(flag==0){//如果不包含元音,输出信息,进行下一次判断
            goto res;
        }

        /*It cannot contain three consecutive vowels or three consecutive consonants. */

        for(i=0;i<len;i++){//统计连续元音辅音字母
            if(inp[i]=='a'||inp[i]=='e'||inp[i]=='i'||inp[i]=='o'||inp[i]=='u'){
                con_v++;con_c=0;
            }else{
                con_v=0;con_c++;
            }
            if(con_v==3||con_c==3){
                flag=0;
                break;
            }
        }

        if(flag==0){//如果包含三个连续元音或辅音,输出信息,进行下一次判断
            goto res;
        }

        /*It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'. */

        for(i=0;i<len-1;i++){//判断连续两个相同字母,e、o除外
            if(inp[i]==inp[i+1]&&inp[i]!='e'&&inp[i]!='o'){
                flag=0;
                break;
            }
        }

res:    if(flag==0){//如果包含三个连续元音或辅音,输出信息,进行下一次判断
            printf("<%s> is not acceptable.\n",inp);
        }else{
            printf("<%s> is acceptable.\n",inp);
        }
        con_v=0;con_c=0;flag=0;//初始化
        cin>>inp;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator