求个问题的思路

durant 2015-03-13 11:04:46


假设串行码流是:654321654321(或者654321654321654)之类的
模块1,2,3,4,5,6的位置是可以任意变化的
但每个位置的进入数据必须依次是1,2,3,4,5,6

请教下思路,我不知道怎么下手了
...全文
124 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿发你好 2015-03-13
  • 打赏
  • 举报
回复
手打的,就这个意思吧,面向对象的写法。
阿发你好 2015-03-13
  • 打赏
  • 举报
回复
class Filter { bool accept(char ch); }; bool do_filter(char ch) { for(int i=0; i<6; i++) { if( fs[i]. accept(ch)) return true; } return false; } main() { Filter fs[6]; const char* text= "123234343534"; for(int i=0; i<strlen(text); i++) { char ch = text[i]; do_filter(ch); } } 推荐一本书:《C/C++学习指南》 http://www.afanihao.cn/c_guide/ ,适用C,也适合C++,一看就懂,“不可能看不懂”。在线阅读,配套答疑平台,实在不懂就直接向作者提问。专业人士编写,与企业标准对接。
FightForProgrammer 2015-03-13
  • 打赏
  • 举报
回复
输入是啥?输出要得到啥?
赵4老师 2015-03-13
  • 打赏
  • 举报
回复
仅供参考:
//qplw.cpp
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int v=0;
int w=0;
int m;//记录字符串长度
int n;//记录字符串中的字符种类数
char map[256];//记录是哪几种字符
int count[256];//记录每种字符有多少个
int stack[1000];//递归用的栈,并记录当前生成的排列
void Make_Map(char *str) {//统计字符串的相关信息
    int s[256];
    int i;
    memset(s,0,sizeof(s));
    memset(count,0,sizeof(count));
    m=strlen(str);
    if (w<1 || m<w) w=m;
    while(*str) {
        s[*str]++;
        str++;
    }
    n=0;
    for (i=0;i<256;i++)
        if (s[i]) {
            map[n]=i;
            count[n]=s[i];
            n++;
        }
}
void Find(int depth) {//递归式回溯法生成全排列
    if (depth==w) {
        int i;
        for (i=0;i<depth;i++) putchar(map[stack[i]]);
        putchar('\n');
    } else {
        int i;
        if (v && depth>0) {
            for (i=0;i<depth;i++) putchar(map[stack[i]]);
            putchar('\n');
        }
        for (i=0;i<n;i++)
            if (count[i]) {
                stack[depth]=i;
                count[i]--;
                Find(depth+1);
                count[i]++;
            }
    }
}
void main(int argc,char**argv) {
    if (argc<2) {
        printf("%s 要产生全排列的字符串 [限定长度|-1]\n",argv[0]);
        return;
    }
    if (argc>=3) w=atoi(argv[2]);
    if (-1==w) v=1;
    Make_Map(argv[1]);
    Find(0);
}
//C:\test>qplw
//qplw 要产生全排列的字符串 [限定长度|-1]
//
//C:\test>qplw 123
//123
//132
//213
//231
//312
//321
//
//C:\test>qplw 123 2
//12
//13
//21
//23
//31
//32
//
//C:\test>qplw 122333 3
//122
//123
//132
//133
//212
//213
//221
//223
//231
//232
//233
//312
//313
//321
//322
//323
//331
//332
//333
//
//C:\test>qplw 123 -1
//1
//12
//123
//13
//132
//2
//21
//213
//23
//231
//3
//31
//312
//32
//321
//

69,379

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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