输入一行数字(数字最长可达20位,整数),数字之间用空格分隔;第二行输入模式数字(长度可达20位整数);按增序输出第一行匹配的数字
因为是大整数,所以输入不能用int存,需要用字符串存储,转化为字符串的匹配与排序(先求长排序,若相等再用strcmp)
用到的函数:
1. strstr() 判断是否是子串
2. strcmp() 字符串比较(字典序)
3. strcpy() 字符串复制
#include <iostream>
#include <cstring>
using namespace std;
void printSortString()
{
char s[1000];
gets(s);
char T[20];//考虑长串数字;
gets(T);
char *data[50];
int i=0;
int j =0;
int k=0;
/**输入格式必须保证数字之间有空格,最后一个数字先空格再回车*/
while(s[i]!='\0')
{
data[j] = (char *)malloc(50);
while(s[i]!=' ')
{
data[j][k++] = s[i++] ;
}
data[j][k]='\0';
j++;
i++;
k=0;
}
char *output[50];
int nu