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));
              }
          }
  • 相关阅读:
    淘宝网的质量属性的六个常见属性场景
    架构漫谈读书笔记
    软件架构师的工作流程
    centos7通过docker安装mysql
    centos7下安装docker
    VMware 虚拟机下CentOS 7连接网络
    在JSP中使用el函数标签获取默认值(男女性别选项)
    ssm登录与退出
    MVC(Model -View-Controller)实例应用模式
    MVC模式
  • 原文地址:https://www.cnblogs.com/sjy123/p/2922488.html
Copyright © 2011-2022 走看看