为什么,逗号后面,还有空格........
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <vector> #include <map> using namespace std; const int maxn=50; int d[maxn][maxn]; map<string,int> mmp; string mpp[maxn]; int n,m; bool vis[maxn]; void init() {memset(vis,0,sizeof(vis));memset(d,0,sizeof(d));mmp.clear(); } int main() { int Case=0;while(~scanf("%d%d",&n,&m)&&(m+n)){if(Case) printf("\n");Case++;init();string s1,s2;int cnt=0;for(int i=1;i<=m;i++){int u,v;cin >> s1 >> s2;if(mmp[s1]) u=mmp[s1];else{u=mmp[s1]=++cnt;mpp[u]=s1;}if(mmp[s2]) v=mmp[s2];else{v=mmp[s2]=++cnt;mpp[v]=s2;}d[u][v]=1;}for(int i=1;i<=n;i++)d[i][i]=1;for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)d[i][j]=(d[i][j]||(d[i][k]&&d[k][j]));printf("Calling circles for data set %d:\n",Case);for(int i=1;i<=n;i++)//标记并输出 {int flag=0;if(!vis[i]){for(int j=1;j<=n;j++)if(d[i][j]&&d[j][i]){if(!vis[j]){if(!flag) flag=1;else printf(", ");//坑啊!!!逗号后面为什么还有空格!!cout << mpp[j];vis[j]=1;}}}if(flag) printf("\n");}}return 0; }