| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 756 人关注过本帖
标题:没什么技术的,可就是找不到错误!哪位帮我看看。。。
只看楼主 加入收藏
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
结帖率:83.33%
收藏
已结贴  问题点数:20 回复次数:10 
没什么技术的,可就是找不到错误!哪位帮我看看。。。
Input Format:

输入N表示有N组测试数据N<=100。

每组测试输入M<=30表示有M个字母,接下来是M串二进制码。
Output format:

有N行,每行输出一串字母。
Input Sample:

2
9
01001 00000 00010 00101 01100 01001 00101 10110 00101
16
11001 01111 10101 00000 00001 10010 00101 00000 10100 01000 00101 00000 00010 00101 10011 10100

Output Sample:

I BELIEVE
YOU ARE THE BEST

输出换行的问题。。。
代码:
#include<stdio.h>
int power(int x,int n2)
{
    if(0==n2)
        return 1;
    else
        return x*power(x,n2-1);
}
int change(int a2,int n1)
{
    int l,result=0,a1[5];
    for(l=4;l>=0;l--)
        a1[l]=(a2/power(10,4-l))%10;
    for(l=0;l<5;l++)
        result+=a1[l]*power(2,4-l);
    return result;
}
int main()
{
    int i,j,k=0,m,n,i1=0,a[100],b[30],a3[100];
    char c[30];
    scanf("%d",&m);
    for(i=0;i<m;i++)
    {
        scanf("%d",&n);
        for(j=0;j<n;j++)
        {    scanf("%d",&a[j]);
            b[i1]=change(a[j],n);
            if(b[i1]==0)
                c[k++]=' ';
            else
                c[k++]=b[i1]+'A'-1;
            i1++;
        }
      a3[i]=k-1;
    }
    j=0;
    for(i=0;i<k;i++)
    {        
        if(i==a3[j++])
        printf("\n");
        printf("%c",c[i]);
    }
    return 0;
}
搜索更多相关主题的帖子: 技术 
2010-04-02 21:51
亚小南
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:69
专家分:136
注 册:2009-11-19
收藏
得分:5 
这程序能通过编译啊
2010-04-02 23:20
亚小南
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:69
专家分:136
注 册:2009-11-19
收藏
得分:0 
希望楼主写程序的时候能注释一下
很难懂
2010-04-02 23:22
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
收藏
得分:0 
回复 3楼 亚小南
帮做的一道ACM题的,把自己也难倒了!还是用指针实现简单。。。20分谁要。。

www.
2010-04-03 00:38
Devil_W
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:9
帖 子:1160
专家分:1797
注 册:2009-9-14
收藏
得分:5 
程序代码:
#include<iostream>
#include<bitset>
#include<map>
using namespace std;
struct compare{

    bool operator()(bitset<5> b1,bitset<5> b2)
        {
            return b1.to_string()<b2.to_string();
        }
};
int main()
{
    map<bitset<5>,char,compare> hash;
    for(int i=1;i<26;i++)
    {
        bitset<5> bs(i);
        hash[bs]='A'+i-1;
    }
    bitset<5> bs(0);
    hash[bs]=(int)' ';
    int sum;
    cin>>sum;
    while(sum--)
    {
        int count;
        cin>>count;
        while(count--)
        {
            bitset<5> tmp;
            cin>>tmp;
            cout<<hash[tmp];
        }
        cout<<endl;
    }

    return 0;
}
2010-04-03 01:31
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
收藏
得分:0 
回复 5楼 Devil_W
缺少#include<string>
尽管与题意不符,但提供一种思路,谢谢啊!

www.
2010-04-03 09:10
新手上路中
Rank: 4
等 级:业余侠客
帖 子:49
专家分:204
注 册:2010-3-26
收藏
得分:5 
好复杂啊
2010-04-03 09:20
Devil_W
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:9
帖 子:1160
专家分:1797
注 册:2009-9-14
收藏
得分:0 
把你的OJ打开,把我的代码贴进去,选择G++编译器,你看能不能过,我觉得是符合你题意的。
2010-04-03 10:12
Devil_W
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:9
帖 子:1160
专家分:1797
注 册:2009-9-14
收藏
得分:0 
-BASH-4.0.35$ cat test.cpp
#include<iostream>
#include<bitset>
#include<map>
using namespace std;
struct compare{

    bool operator()(bitset<5> b1,bitset<5> b2)
        {
            return b1.to_string()<b2.to_string();
        }
};
int main()
{
    map<bitset<5>,char,compare> hash;
    for(int i=1;i<26;i++)
    {
        bitset<5> bs(i);
        hash[bs]='A'+i-1;
    }
    bitset<5> bs(0);
    hash[bs]=(int)' ';
    int sum;
    cin>>sum;
    while(sum--)
    {
        int count;
        cin>>count;
        while(count--)
        {
            bitset<5> tmp;
            cin>>tmp;
            cout<<hash[tmp];
        }
        cout<<endl;
    }

    return 0;
}

-BASH-4.0.35$ gmake
g++ -g3  -c test.cpp -o test.o  
g++ -g3  -o test test.o
-BASH-4.0.35$
-BASH-4.0.35$ cat input
2
9
01001 00000 00010 00101 01100 01001 00101 10110 00101
16
11001 01111 10101 00000 00001 10010 00101 00000 10100 01000 00101 00000 00010 00101 10011 10100-BASH-4.0.35$
-BASH-4.0.35$ ./test <input
I BELIEVE
YOU ARE THE BEST
-BASH-4.0.35$


你觉得我有可能把错误的代码往这里贴吗?
你用vc编译也许是需要string这个头文件的。

g++可以不要。
2010-04-03 10:56
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:5 
这样子就行了!
        if(i==a3[j++])
        printf("\n");
改成:
        if (i==a3[j])
        {printf("\n");j++;}

★★★★★为人民服务★★★★★
2010-04-03 11:18
快速回复:没什么技术的,可就是找不到错误!哪位帮我看看。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017019 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved