while 放的位置不對,參考下列的寫法吧
#include <iostream>
using namespace std;
int main() {
string s;
while(cin >> s){
cout << "hello, "<< s << endl;
}
return 0;
}
我也超时,求解:
/**********************************************************************************/
/* Problem: a002 "簡易加法" */
/* Language: CPP (1044 Bytes) */
/* Result: NA(score:10) judge by this@ZeroJudge */
/* Author: Guest_ at 2013-07-06 10:26:54 */
/**********************************************************************************/
#include<cstdio>
#include<queue>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int ans,s,t,a,b,n,m,vt,maxflow,v[100010],w[100010],u[100010],path[2010],z[100010],next[100010],head[2010],dis[2010];
void add(int a,int b,int c,int d){
v[++vt]=b;
u[vt]=a;
w[vt]=c;
z[vt]=d;
next[vt]=head[a];
head[a]=vt;
v[++vt]=a;
u[vt]=b;
w[vt]=0;
z[vt]=-d;
next[vt]=head[b];
head[b]=vt;
}
bool spfa(){
memset(dis,63,sizeof(dis));
dis[s]=0;
queue<int>q;
q.push(s);
while(!q.empty()){
int now=q.front();q.pop();
for(int i=head[now];i;i=next[i])
if(w[i]&&dis[now]+z[i]<dis[v[i]]){
dis[v[i]]=dis[now]+z[i];
path[v[i]]=i;
q.push(v[i]);
}
}
return dis[t]<dis[0];
}
int main(){
while(scanf("%d%d",&a,&b)!=EOF) {
s=3;t=s+1;vt=1;
add(s,t,1,a);
add(s,t,1,b);
while(spfa()){
int minx=0x7FFFFFF,p=t;
for(;p!=s;p=u[path[p]])minx=min(minx,w[path[p]]);
p=t;
ans+=dis[t]*minx;
maxflow+=minx;
for(;p!=s;p=u[path[p]]){
w[path[p]]-=minx;
w[path[p]^1]+=minx;
}
}
printf("%d\n",ans);}
return 0;
}