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

你可能感兴趣的文章
Nmap哪些想不到的姿势
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
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
查看>>