nyoj1188
来源:互联网 发布:诺基亚800下载软件 编辑:程序博客网 时间:2024/05/16 08:52
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1188;
直接模拟,貌似我这种写法很快啊,哈哈
#include<stdio.h>#include<algorithm>using namespace std;#include<string.h>typedef struct{ char a[20];} node;bool cmp(node a,node b){ return strcmp(a.a,b.a)<0;}int main(){ int i; char a[510]; char b[510]; char s1[510]; char s2[510]; char k[510]; node qa[510],qb[510],qc[510]; while(gets(a)) { gets(b); scanf("%s %s",s1,s2); int count=0,counta=0,countb; for(i=0; i<strlen(a); i++) { if(a[i]==' ') { count=0; strcpy(qa[counta++].a,k); memset(k,0,sizeof(k)); } else k[count++]=a[i]; } strcpy(qa[counta++].a,k); memset(k,0,sizeof(k)); sort(qa,qa+counta,cmp); int countbb=0; countb=0; for(i=0; i<strlen(b); i++) { if(b[i]==' ') { countbb=0; strcpy(qb[countb].a,k); countb=countb+1; memset(k,0,sizeof(k)); } else k[countbb++]=b[i]; } strcpy(qb[countb++].a,k); memset(k,0,sizeof(k)); int aa=0; for(i=0; i<counta; i++) { if(strcmp(qa[i].a,qa[i+1].a)!=0) { strcpy(qa[aa++].a,qa[i].a); } else continue; } int bb=0; for(i=0; i<countb; i++) { if(strcmp(qb[i].a,qb[i+1].a)!=0) { strcpy(qb[bb++].a,qb[i].a); } else continue; } int cc=0; for(i=0; i<aa; i++) { strcpy(qc[cc++].a,qa[i].a); } for(i=0; i<bb; i++) strcpy(qc[cc++].a,qb[i].a); sort(qc,qc+cc,cmp); int ccc=0; for(i=0; i<cc; i++) { if(strcmp(qc[i].a,qc[i+1].a)!=0) strcpy(qc[ccc++].a,qc[i].a); } for(i=0; i<ccc; i++) printf("%s ",qc[i].a); printf("\n"); for(i=0; i<aa; i++) { int flag=0; for(int j=0; j<bb; j++) { if(strcmp(qa[i].a,qb[j].a)==0) { flag=1; } } if(flag) printf("%s ",qa[i].a); } printf("\n"); for(i=0; i<ccc; i++) { if(strcmp(qc[i].a,s1)>=0&&strcmp(qc[i].a,s2)<=0) { printf("%s ",qc[i].a); } } printf("\n"); getchar(); }}
0 0
- nyoj1188
- leetcode[151]:Reverse Words in a String
- 派生关系中的二义性处理
- BestCoder 1st Anniversary ($) 1002.Hidden String
- [LeetCode]Lowest Common Ancestor of a Binary Tree
- HDU 5312(数学推导+技巧)
- nyoj1188
- 51单片机学习笔记【八】——步进电机
- IT 技术人必须思考的 15 个问题
- STL学习顺序
- BestCoder 1st Anniversary
- 操作系统内存管理之 内部碎片vs外部碎片
- 【Thinking in Java笔记】为什么需要内部类
- Eclipse开发Android程序如何在手机上运行
- !leetcode[162]:Find Peak Element