把以下转为c语言#include <iostream> #include <cstring> using namespace std; int statck[1000000]; int status[100]; double res[100]; class num { public: int end; double val; int next; }a[1000000]; int b[100]; int sum[100],tag,w; string s1[100]; int n; int main() { void deal(int k); int i,j,m,s,t,x,y,z; string s2,s3; double val; t=1; while(cin>>n) { if(!n) { break; } for(i=1;i<=n;i++) { cin>>s1[i]; } cin>>m; memset(b,-1,sizeof(b)); z=0; for(i=1;i<=m;i++) { cin>>s2; cin>>val; cin>>s3; for(j=1;j<=n;j++) { if(s1[j]==s2) { x=j; } if(s1[j]==s3) { y=j; } } a[z].end=y; a[z].val=val; a[z].next=b[x]; b[x]=z; z++; } for(i=1;i<=n;i++) { tag=0; deal(1); if(tag==1) { break; } } cout<<"Case "<<t<<" "; t++; if(i==n+1) { cout<<"No"<<endl; }else { cout<<"Yes"<<endl; } } return 0; } void deal(int k) { int i,j,base,top; int x; for(i=1;i<=n;i++) { res[i]=0; } res[k]=100.0; base=top=0; memset(status,0,sizeof(status)); memset(sum,0,sizeof(sum)); statck[top++]=k; status[k]=1; sum[k]+=1; w=0; while(base<top) { x=statck[base]; base++; status[x]=0; for(j=b[x];j!=-1;j=a[j].next) { if((res[x]*a[j].val)>res[a[j].end]) { res[a[j].end]=res[x]*a[j].val; if(status[a[j].end]==0) { sum[a[j].end]+=1; statck[top++]=a[j].end; status[a[j].end]=1; if(sum[a[j].end]>=n) { tag=1; break; } } } } if(j!=-1) { break; } } }
时间: 2023-12-13 16:04:46 浏览: 130
以下是将该代码转换为 C 语言的过程:
```c
#include <stdio.h>
#include <string.h>
#define MAXN 100
#define MAXM 1000000
int stack[MAXM], status[MAXN], b[MAXN], sum[MAXN];
double res[MAXN];
struct num {
int end, next;
double val;
} a[MAXM];
char s1[MAXN][MAXN], s2[MAXN][MAXN];
int n, m, t, z, tag, w;
void deal(int k);
int main() {
int i, j, s, t, x, y;
double val;
t = 1;
while (scanf("%d", &n) != EOF) {
if (!n) {
break;
}
for (i = 1; i <= n; i++) {
scanf("%s", s1[i]);
}
scanf("%d", &m);
memset(b, -1, sizeof(b));
z = 0;
for (i = 1; i <= m; i++) {
scanf("%s%lf%s", s1, &val, s2);
for (j = 1; j <= n; j++) {
if (strcmp(s1, s1[j]) == 0) {
x = j;
}
if (strcmp(s2, s1[j]) == 0) {
y = j;
}
}
a[z].end = y;
a[z].val = val;
a[z].next = b[x];
b[x] = z;
z++;
}
for (i = 1; i <= n; i++) {
tag = 0;
deal(i);
if (tag == 1) {
break;
}
}
printf("Case %d ", t);
t++;
if (i == n + 1) {
printf("No\n");
} else {
printf("Yes\n");
}
}
return 0;
}
void deal(int k) {
int i, j, base, top, x;
for (i = 1; i <= n; i++) {
res[i] = 0;
}
res[k] = 100.0;
base = top = 0;
memset(status, 0, sizeof(status));
memset(sum, 0, sizeof(sum));
stack[top++] = k;
status[k] = 1;
sum[k]++;
w = 0;
while (base < top) {
x = stack[base];
base++;
status[x] = 0;
for (j = b[x]; j != -1; j = a[j].next) {
if ((res[x] * a[j].val) > res[a[j].end]) {
res[a[j].end] = res[x] * a[j].val;
if (status[a[j].end] == 0) {
sum[a[j].end]++;
stack[top++] = a[j].end;
status[a[j].end] = 1;
if (sum[a[j].end] >= n) {
tag = 1;
break;
}
}
}
}
if (j != -1) {
break;
}
}
}
```
注意,以上代码只是简单的将原有的 C++ 代码转换为 C 代码,为了使代码更加规范和易读,可能需要进一步修改和调整。同时,这段代码实现的功能涉及到外汇交易和套汇问题,这些问题需要遵守法律法规,建议在合法的情况下使用。
阅读全文