博客
关于我
2020-12-03本题要求实现函数,可以根据下表查找到星期,返回对应的序号。
阅读量:633 次
发布时间:2019-03-14

本文共 742 字,大约阅读时间需要 2 分钟。

本题要求实现函数,可以根据下表查找到星期,返回对应的序号。

序号 星期
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday

函数接口定义:

int getindex( char *s );

 

函数getindex应返回字符串s序号。如果传入的参数s不是一个代表星期的字符串,则返回-1。

裁判测试程序样例:

#include 
#include
#define MAXS 80int getindex( char *s );int main(){ int n; char s[MAXS]; scanf("%s", s); n = getindex(s); if ( n==-1 ) printf("wrong input!\n"); else printf("%d\n", n); return 0;}/* 你的代码将被嵌在这里 */

 

输入样例1:

Tuesday

 

输出样例1:

2

 

输入样例2:

today

 

输出样例2:

wrong input!

int getindex(char *s){

    int week;
    char *ch[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Staturday"};
    
    for(week=0;week<7;week++){
    
        if(strcmp(s,ch[week])==0){
        
            break;
        }
         else if(week==7){
        
             return -1;
        }

    

         return week;
    }

}

 

转载地址:http://ddooz.baihongyu.com/

你可能感兴趣的文章
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>