关注
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
char out[100][300];
int lon[100];
int r=0,k=0;
while(~scanf("%s",str)){
for(int i=0,len=strlen(str);i<len;i++)//拆分
{
if(str[i]>='1'&&str[i]<='9'){
if(str[i+1]<'1'||str[i+1]>'9'){//一位数字
memcpy(out[k++],&str[r],i-r+1);
r=i+1;
i=r;
}
else //两位数字
{
memcpy(out[k++],&str[r],i+1-r+1);
r=i+2;
i=r;
}
}
}
int len2;
char tm[50];
for(int i=0;i<k;i++){//lon录值
len2=strlen(out[i]);
for(int j=0;j<len2;j++){
if(out[i][j]>='1'&& out[i][j]<='9'){
if(len2-j==1)//一位数字
{
lon[i]=(int)out[i][j]-48;
out[i][j]='\0';
}
else
if(len2-j==2)
{
lon[i]=((int)out[i][j]-48)*10+(int)out[i][j+1]-48;
out[i][j+1]='\0';
out[i][j]='\0';
break;
}
}
}
}
int q;
char tmp[50];
for(int i=0;i<k;i++)
for(int h=0;h<k-1;h++){
if(lon[h]>lon[h+1]){
q=lon[h];
lon[h]=lon[h+1];
lon[h+1]=q;
memcpy(tmp,out[h],strlen(out[h]));
memset(out[h],0,strlen(out[h]));
memcpy(out[h],out[h+1],strlen(out[h+1]));
memset(out[h+1],0,strlen(out[h+1]));
memcpy(out[h+1],tmp,strlen(tmp));
memset(tmp,0,strlen(tmp));
}
}
for(int i=0;i<k;i++){
for(int g=0;g<lon[i];g++)
printf("%s",out[i]);
}
}
return 0;
}
我的第三题代码,自测通过,没时间做。。。。忧伤
查看原帖
点赞 2
相关推荐
01-04 20:58
淮北师范大学 Java 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 牛客新年AI问运 #
6242次浏览 110人参与
# 工作中的卑微时刻 #
33391次浏览 199人参与
# 牛客AI体验站 #
16202次浏览 286人参与
# 多益网络工作体验 #
63119次浏览 306人参与
# 有必要和同事成为好朋友吗? #
955次浏览 21人参与
# 正在实习的碎碎念 #
1644786次浏览 13716人参与
# 面试中的破防瞬间 #
1190083次浏览 11026人参与
# 工作一周年分享 #
52296次浏览 274人参与
# 滴!实习打卡 #
786448次浏览 6841人参与
# 秋招吐槽大会 #
304219次浏览 1523人参与
# 机械人的薪资开到多少,才适合去? #
165000次浏览 571人参与
# 你最满意的offer薪资是哪家公司? #
71361次浏览 353人参与
# 大学最后一个寒假,我想…… #
89248次浏览 809人参与
# 你怎么看待AI面试 #
145959次浏览 786人参与
# 哪些公司真双非友好? #
62856次浏览 268人参与
# OC/开奖 #
411214次浏览 2282人参与
# 为了实习逃课值吗? #
65725次浏览 526人参与
# 如果可以选,你最想从事什么工作 #
721867次浏览 4870人参与
# 重来一次,你会对开始求职的自己说 #
32783次浏览 388人参与
# 如何提高实习转正率? #
86485次浏览 504人参与
查看17道真题和解析