#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct xx
{
char qq[101];
}x[101];
int cmp(const void *x, const void *y)
{
struct xx x1 = *(struct xx *)x;
struct xx y1 = *(struct xx *)y;
if(strcmp(x1.qq, y1.qq) > 0) return 1;
return 0;
}
int main()
{
char s[101];
int n;
while(~scanf("%s", s))
{
int ant = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%s", x[i].qq);
qsort(x, n, sizeof(x[0]), cmp);
for(int i = 0; i < n; i++)
{
if(strstr(x[i].qq, s) - x[i].qq == 0)
{
printf("%s\n", x[i].qq);
break;
}
else ant++;
}
if(ant == n) puts(s);
}
return 0;
}
杭电53A题,实在不知道哪里错了,想让大神们帮忙看一下,代码错到11组
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答
- ysuwood 2015-12-27 10:02关注
对,我搞错了,试试这个:
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct xx { char qq[101]; }x[101]; int cmp(const void *x, const void *y) { struct xx x1 = *(struct xx *)x; struct xx y1 = *(struct xx *)y; return strcmp(x1.qq, y1.qq);//修改 } int main() { char s[101]; int i,n;//修改 while(~scanf("%s", s)) { scanf("%d", &n); for( i = 0; i < n; i++) scanf("%s", x[i].qq); qsort(x, n, sizeof(x[0]), cmp); for( i = 0; i < n; i++) { if(strstr(x[i].qq, s) - x[i].qq == 0) { printf("%s\n", x[i].qq); break; } } if(i >= n) puts(s); } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
- ¥15 js调用html页面需要隐藏某个按钮
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?
- ¥20 java项目连接sqlserver时报ssl相关错误
- ¥15 一道python难题3
- ¥15 牛顿斯科特系数表表示
- ¥15 arduino 步进电机
- ¥20 程序进入HardFault_Handler
- ¥15 oracle集群安装出bug