当前位置:网站首页>Exercise 11-2 find week (15 points)
Exercise 11-2 find week (15 points)
2022-06-11 22:25:00 【Xiaoyan y】
This problem requires the implementation of functions , You can find the week according to the table below , Return the corresponding serial number .
| Serial number | week |
|---|---|
| 0 | Sunday |
| 1 | Monday |
| 2 | Tuesday |
| 3 | Wednesday |
| 4 | Thursday |
| 5 | Friday |
| 6 | Saturday |
Function interface definition :
int getindex( char *s );
function getindex Should return string s Serial number . If the parameter passed in s It's not a string representing the week , Then return to -1.
Sample referee test procedure :
#include <stdio.h>
#include <string.h>#define MAXS 80
int 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;
}/* Your code will be embedded here */
sample input 1:
Tuesday
sample output 1:
2
sample input 2:
today
sample output 2:
wrong input!
int getindex( char *s ){
char *ch[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int i;
for(i=0;i<7;i++){
if(strcmp(s,ch[i])==0){
return i;
}
}
return -1;
}
边栏推荐
猜你喜欢

详解异步任务:函数计算的任务触发去重

【解决】修改子物体Transform信息导致变换不对称、异常问题的解决方案

SVN本地部署server和cleint 并用阿里云盘自动备份

Lecture de l'article dense Visual SLAM for RGB - D Cameras
![[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials](/img/64/683a190d14406a9971edd79037cc97.jpg)
[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials

Analysis of the implementation principle of an open source markdown to rich text editor

Zhanrui IOT chip 8910dm is certified by Deutsche Telekom

Prefabricated dishes in the trillion market have also begun to roll inside. How can brands stand out in the fierce competition?

C language implements eight sorts of sort merge sort

学1个月爬虫就月赚6000?别被骗了,老师傅告诉你爬虫的真实情况
随机推荐
leetcode 257. Binary tree paths all paths to a binary tree (simple)
BUUCTF(5)
习题9-1 时间换算 (15 分)
学1个月爬虫就月赚6000?别被骗了,老师傅告诉你爬虫的真实情况
Daily question -1317 Converts an integer to the sum of two zero free integers
Win10弹出USB时出现该设备正在使用的解决方法
[Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
习题6-6 使用函数输出一个整数的逆序数 (20 分)
Custom implementation offsetof
3.2 naming rules of test classes
使用VBScript读取网络的日志数据进行处理
玩家必读|Starfish NFT进阶攻略
批改网高分短语&句型
A simple example of linear regression in machine learning
Start notes under the Astro Pro binocular camera ROS
被忽略的技巧:位运算
[Matlab]二阶节约响应
3.3 naming rules of test modules
Stack栈的实现
[uniapp native plug-in] shangmi cashbox plug-in