C语言实现:
while(~scanf("%d%d", &n, &m)){
}
或
while(scanf("%d %d",&n,&m)!=EOF){
C++实现:
while(cin>>n>>m){