| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 436 人关注过本帖
标题:字符反串问题
只看楼主 加入收藏
wbq777
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-6-24
结帖率:66.67%
收藏
已结贴  问题点数:10 回复次数:2 
字符反串问题
Problem Description
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output
For each test case, you should output the text which is processed.
 
Sample Input
3
olleh !dlrow
m'I morf .udh
I ekil .mca
 
Sample Output
hello world!
I'm from hdu.
I like acm.
题目意思很简单,看下范例就知道了。。问题就是我不会、我编了个狗P不通的程序。。。很纠结!
本人程序:
#include"stdio.h"
#include"string.h"
int main()
{
    int i,a,n,j;
    char c[1000],c1[1000],d[2];
    scanf("%d",&n);
    gets(d);
    i=0;
    while(i<n)
    {
        a=0;
        gets(c);
        for(i=0;c[i]!='\0';i++)
        {
            if(c[i]==' ')
            {
                for(j=a;j<=i;j++)
                {
                    c1[j]=c1[i-j];
                }
                c1[j]=' ';
                a=j;   
            }
        }
        puts(c1);
    }
}
搜索更多相关主题的帖子: single several written number should 
2011-08-10 16:19
ppfly
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:297
专家分:1956
注 册:2009-5-17
收藏
得分:6 
程序代码:
#include<stdio.h>
#include<string.h>
void strRevg(char *str,int lgth)
{
    int i;
    char temp;
    lgth--;
    for(i=0;i<lgth-i;i++)
    {
        temp=*(str+i);
        *(str+i)=*(str+lgth-i);
        *(str+lgth-i)=temp;
    }
}
int main()
{
    int T,i,j;
    char str[1003]="\0";
    scanf("%d",&T);
    getchar();
    while(T--)
    {
        gets(str);
        i=0;j=0;
        while(str[i]!='\0')
        {
            while(str[i]!=' ' && str[i]!='\0')i++;
            strRevg(str+j,i-j);
            while(str[i]==' ')i++;
            j=i;
        }
        printf("%s\n",str);
    }
    return 0;
}


[ 本帖最后由 ppfly 于 2011-8-10 16:29 编辑 ]

********多贴代码,少说空话*******
2011-08-10 16:24
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:4 
可以试试找个测试错误例子自己调试一下

                                         
===========深入<----------------->浅出============
2011-08-10 16:26
快速回复:字符反串问题
数据加载中...
 
   



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

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