zoukankan      html  css  js  c++  java
  • [结题报告]12289 OneTwoThree Time limit: 1.000 seconds


      One-Two-Three 

    Your little brother has just learnt to write one, two and three, in English. He has written a lot of those words in a paper, your task is to recognize them. Note that your little brother is only a child, so he may make small mistakes: for each word, there might be at most one wrong letter. The word length is always correct. It is guaranteed that each letter he wrote is in lower-case, and each word he wrote has a unique interpretation.

    Input 

    The first line contains the number of words that your little brother has written. Each of the following lines contains a single word with all letters in lower-case. The words satisfy the constraints above: at most one letter might be wrong, but the word length is always correct. There will be at most 10 words in the input.

    Output 

    For each test case, print the numerical value of the word.

    Sample Input 

    3
    owe
    too
    theee
    

    Sample Output 

    1
    2
    3

    参考代码:
    根据题给信息,这个小朋友写出的单词长度保证,而且保证只错一个字母,所以我首先判断单词长度,3是5个字母,所以比较字母长度即可,two,one选择其中一个用if语句判断一下就好。我选用的是2,具体判断看下面代码.
    #include"stdio.h"
    #include"string.h"
    int fun(char *s)
    {
        int len = strlen(s);
        
        if (len == 5)
            return 3;
        else 
            if ((s[0]=='t' && s[1]=='w') || (s[0]=='t' && s[2]=='o') || (s[1]=='w' && s[2]=='o'))
                return 2;
        return 1;    
    }
    main()
    { int n,m;
      char a[10];
      scanf("%d ",&n);
      while(n--)
      {gets(a);
       printf("%d\n",fun(a));
              }
          }
  • 相关阅读:
    【2021-03-03】人生十三信条
    【2021-03-02】勤奋和努力是积极乐观的自然导向
    【2021-03-01】解铃还需系铃人
    【2021-02-28】人生十三信条
    【2021-02-27】人生十三信条
    【2021-02-26】人生十三信条
    【2021-02-25】“活到老,做到老”的观念趋势
    【一句日历】2021年3月
    【2021-02-24】理想化中的积极进取精神
    机器人走方格
  • 原文地址:https://www.cnblogs.com/sjy123/p/2922488.html
Copyright © 2011-2022 走看看