复制字符串

复制字符串

时间: 1ms        内存:128M

描述:

有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。

输入:

数字n 一行字符串数字m

输出:

从m开始的子串

示例输入:

6
abcdef
3

示例输出:

cdef

提示:

参考答案(内存最优[748]):


struct  
{int year;  
 int month;  
 int day;  
}date;  
main()  
{int days;
//printf("Input  year,month,day:");
scanf("%d%d%d",&date.year,&date.month,&date.day);
switch(date.month)  
 {case 1: days=date.day;    break;  
 case 2: days=date.day+31; break;  
 case 3: days=date.day+59; break;  
 case 4: days=date.day+90; break;  
 case 5: days=date.day+120;break;  
case 6: days=date.day+31; break;  
   case 7: days=date.day+181; break;  
   case 8: days=date.day+212; break;  
case 9: days=date.day+243; break;  
case 10: days=date.day+273; break;  
case 11: days=date.day+304; break;  
case 12: days=date.day+334; break;  
}  
if((date.year%4==0&&date.year%100!=0||date.year%400==0)&&date.month>=3)days+=1;  
printf("%d",days);  
}

参考答案(时间最优[0]):


struct  
{int year;  
 int month;  
 int day;  
}date;  
main()  
{int days;
//printf("Input  year,month,day:");
scanf("%d%d%d",&date.year,&date.month,&date.day);
switch(date.month)  
 {case 1: days=date.day;    break;  
 case 2: days=date.day+31; break;  
 case 3: days=date.day+59; break;  
 case 4: days=date.day+90; break;  
 case 5: days=date.day+120;break;  
case 6: days=date.day+31; break;  
   case 7: days=date.day+181; break;  
   case 8: days=date.day+212; break;  
case 9: days=date.day+243; break;  
case 10: days=date.day+273; break;  
case 11: days=date.day+304; break;  
case 12: days=date.day+334; break;  
}  
if((date.year%4==0&&date.year%100!=0||date.year%400==0)&&date.month>=3)days+=1;  
printf("%d",days);  
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注