博客
关于我
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/

你可能感兴趣的文章
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>