面试题

hualin007 2005-10-09 02:59:41
输入:11111输出:5,1,
输入:22222输出:5,2,
输入:12345输出:-5,1,2,3,4,5,
输入:11223输出:2,1,2,2,1,3,
输入:12222输出:1,1,4,2,
输入:12344输出:-3,1,2,3,2,4,
...全文
387 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
hualin007 2005-10-10
  • 打赏
  • 举报
回复
能不能用c语言写出来呢?
hualin007 2005-10-10
  • 打赏
  • 举报
回复
告诉大家这个程序的愿意:就是压缩字符串,给你一个字符串,如果碰到连续相同的字符就用字符的个数和这个字符来表示,比如:aaaaa输出就是5,a,如果是bbbbb,输出就是5,b,但如果不同,就要输出不同的个数和不同的字符,比如abcde,输出就是-5,a,b,c,d,e,可以交叉,但规律就是入此,比如aaabc输出就是3,a,-2,b,c,
大家明白了吗?我的邮箱是ydj007@tom.com
qq:46921920
hualin007 2005-10-10
  • 打赏
  • 举报
回复
很了不起,一看代码就知道是个高手,佩服,向你学习!!!给分!
bugatti 2005-10-10
  • 打赏
  • 举报
回复
o
前面的include好像少了个#
要不你把你的邮箱告诉我 ,我直接把源文件发给你把
bugatti 2005-10-10
  • 打赏
  • 举报
回复
可以运行的
我能运行的阿
zhxk 2005-10-10
  • 打赏
  • 举报
回复
就这些吗?
str=input()
if (str=="11111")
printf("5,1");
else if (str=="22222")
printf("5,2");
else if (str=="12345")
.....
哈哈
你出这个题目是什么意思?说清楚些

hualin007 2005-10-10
  • 打赏
  • 举报
回复
什么鸟程序,运行不了
naponean 2005-10-10
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
bool IsDigital(string str)
{
for(int i=0;i<str.size();i++)
{
if(str[i]>48+9||str[i]<48)
return false;
}
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
string str;
for(;;)
{
cin>>str;
if(str=="exit")
break;
if(!IsDigital(str))
{
cout<<"not digital"<<'\n';
continue;
}
int currentNum,oldNum=-1,time;
int* unRepeatNum=new int[str.size()];
for(int i=0;i<str.size();i++)
{
currentNum=str[i]-48;
if(oldNum==-1)
{
oldNum=currentNum;
unRepeatNum[0]=1;
unRepeatNum[unRepeatNum[0]]=currentNum;
time=1;
}
else if(oldNum==currentNum)
{
if(unRepeatNum[0]==1)
{
time++;
}
else
{
if(unRepeatNum[0]==2)
cout<<1<<","<<unRepeatNum[1]<<",";
else
{
cout<<-unRepeatNum[0]+1<<",";
for(int i=1;i<unRepeatNum[0];i++)
cout<<unRepeatNum[i]<<",";
}
oldNum=currentNum;
unRepeatNum[0]=1;
unRepeatNum[unRepeatNum[0]]=currentNum;
time=2;

}
}
else
{
if(time==1)
{
oldNum=currentNum;
unRepeatNum[0]++;
unRepeatNum[unRepeatNum[0]]=currentNum;
}
else
{
cout<<time<<","<<oldNum;
oldNum=currentNum;
unRepeatNum[0]=1;
unRepeatNum[unRepeatNum[0]]=currentNum;
time=1;
}
}

}
if(time>1)
cout<<time<<","<<oldNum<<","<<endl;
else
{
if(unRepeatNum[0]==1)
cout<<1<<","<<unRepeatNum[1]<<","<<endl;
else
{
cout<<-unRepeatNum[0]<<",";
for(int i=1;i<=unRepeatNum[0];i++)
cout<<unRepeatNum[i]<<",";
cout<<endl;
}
}
}
}
bugatti 2005-10-09
  • 打赏
  • 举报
回复
效率不高
呵呵
而且占用太多存储空间
bugatti 2005-10-09
  • 打赏
  • 举报
回复
写出来了
难啊
运行环境tc20
include<stdio.h>
main()
{int a[8]={1,1,2,3,5,4,4,7};
int b[30];
int c[30];
int length;
int i=0;
int j=0;
int k=1;
int m;
int n;
int p;
int q;
int t;
while(i<8)
{k=1;
while(a[i]==a[++i])
k++;
b[j++]=k;
b[j++]=a[i-1];
}
length=j;
printf("\n");
for(t=0;t<length;t++)
printf("%d",b[t]);


m=0; /*m is the flag of b,n is the flag of c*/
n=0;
while(m<length-1)
{if(b[m]!=1)
{c[n++]=b[m++];
c[n++]=b[m++];}
else
{
for(p=1,q=m;b[m+2]==1&&m<length-1;m=m+2)
p++;
m=m+2;
c[n++]=(-1)*p;
for(k=0;k<p;k++)
{c[n++]=b[q+1];
q=q+2;}
}
}
printf("\n");
for(t=0;t<n;t++)
printf("%d",c[t]);
}
hualin007 2005-10-09
  • 打赏
  • 举报
回复
效率再低,能写出来就算你强
bugatti 2005-10-09
  • 打赏
  • 举报
回复
呵呵
想到了一个
不过效率有点低了
就是先按顺序写下,在归并
hualin007 2005-10-09
  • 打赏
  • 举报
回复
是2,1,-4,2,3,4,5,
bugatti 2005-10-09
  • 打赏
  • 举报
回复
hehe
我想问那要是112345
应该怎么写呢?
是2,1,-3,2,3,4,5吗?
hualin007 2005-10-09
  • 打赏
  • 举报
回复
-5是因为后面有5个数各不相同,-3也是这个原因
snowbirdfly 2005-10-09
  • 打赏
  • 举报
回复
输入:12345输出:-5,1,2,3,4,5,
对了,前面的-5是怎么来的啊??
输入:12344输出:-3,1,2,3,2,4,
-3是怎么来的啊??
KannyFu 2005-10-09
  • 打赏
  • 举报
回复
晕,一天这个问题文了3遍了:)
antijpn 2005-10-09
  • 打赏
  • 举报
回复
非技术

15,445

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧