简单字符串

简单字符串

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

给你一个由'0'-'9'组成的字符串s ( 1 <= s 的长度 <= 100 ),和一个正整数n(1<=n<=3)。
我们将所有的'0'都看成空格。
这样你就得到几个分隔开来的字符串。
输出第n个字符串。题目保证分隔开来的字符串的数量大于等于n。

Input

第一行输入正整数T(1<=T<=100),代表T组测试数据。
对于每一组测试数据由一行组成:
给你一个字符串s和一个正整数n.

Output

对于每一组测试数据,输出分隔后的第n个字符串。

Sample Input

2
123456 1
001230234094500 3

Sample Output

123456
945

Hint

扫描二维码关注公众号,回复: 5396978 查看本文章

Source

#include<stdio.h>
int main()
{
    int t ;
    int n ;
    int i , j ;
    char a[101];
    int d;
    int f;
    scanf("%d",&t);
    for(d=0;d<t;d++)
    {
        j=0;
        scanf("%s %d",a,&n);
        if(a[0]!='0')
            j=1;
        for(i=0;a[i]!='\0';i++)
        {
            if(j==n)
            {
                if(a[0]=='0')
                {
                for(f=i;a[f]!='\0';f++)
                {
                    printf("%c",a[f]);
                    if(a[f+1]=='0')
                    {
                        break;
                    }
                }
                }
                else
                {
                        for(f=i;a[f]!='\0';f++)
                        {
                            printf("%c",a[f]);
                        if(a[f+1]=='0')
                            break;
                        }
                }
                break;
            }
            if(a[i]=='0'&&a[i+1]!='0')
            j++;
            else continue;

        }
         printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43345339/article/details/85019193