http://acm.hdu.edu.cn/showproblem.php?pid=1259
按题目意思,依次交换即可,本来想用个标记变量记录J的位置以提高运行速度的,后来暴力代码交上去后发现0MS,想想就算了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<string.h> int main() { int x,y,n,m,i; char s[10],temp; scanf("%d",&n); while(n--) { strcpy(s,"ZJUTACM"); scanf("%d",&m); while(m--) { scanf("%d%d",&x,&y); temp=s[x-1]; s[x-1]=s[y-1]; s[y-1]=temp; } for(i=0;i<10;i++) if(s[i]=='J') { printf("%d\n",i+1); break; } } return 0; }