| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 652 人关注过本帖
标题:怎么样从程序出发来管理输入流,使程序在读入约定个字符后不在读入
只看楼主 加入收藏
Naturelove
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-10-1
收藏
 问题点数:0 回复次数:2 
怎么样从程序出发来管理输入流,使程序在读入约定个字符后不在读入
#include<iostream>
#define NULL 0

using namespace std;
struct data
{
    int num;//序号
    int x;//密码
    data *next;
};
int find(int,int);
data *creat(int);
int main()
{   

    int m=0,n=0;
    cout<<"The programme will end up with m=0!"<<endl<<endl;
    for(int count=0;;count++)
    {       cout<<"intput your data(m and n):"<<"  ";
             cin>>m;
        
        if(m<=0){cout<<"测试结束,测试组数:"<<count<<endl;break;}
            cin>>n;
               
        if(n<=0){cout<<"n<=0,error!"<<endl<<endl;continue;}
            find(m,n);
    }
    return 0;
}
data *creat(int i)
{
    data *tail=NULL;
    data *head ,*p1,*p2;head=p1=p2=NULL;
    cout<<"Input your passwords(>0):"<<"  ";
    for(int n=1;n<=i;n++)
    {  
        p2=new data;
        cin>>p2->x;
        p2->num=n;
        if(n==1)head=p2;
        else p1->next=p2;
        p1=p2;  
    }
    p1->next=head;
    tail=p1;
    return tail;
}
int find(int m,int n)
{  data *tem=NULL;
    tem=creat(n);//尾指针
    cout<<"The right order is:"<<"  ";
   do
   {
         if(m%n!=0)m=m%n;
        else m=n;
         for(int count=1;count<m;count++)
        {     
            tem=tem->next;
        }
        m=tem->next->x,cout<<tem->next->num<<' ';//取出密码,输出序号
        data *p=NULL;
        p=tem->next;
        tem->next=p->next;
        delete p;
   }while(--n);
    cout<<endl<<endl;
    return 0;
}
    
    我的这段代码,1 5 20 7↙ 它把最后一个20在第二次执行时付给了m,把7给了n。我不想让程序怎么做。请问大家怎么样在输入流上进行控制使满足要求
搜索更多相关主题的帖子: 字符 约定 管理 输入 
2008-10-19 22:06
Naturelove
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-10-1
收藏
得分:0 
我自己顶!!

Any difficulty is to make me strong.
2008-10-21 22:22
zxwangyun
Rank: 4
来 自:云南
等 级:业余侠客
威 望:1
帖 子:232
专家分:299
注 册:2008-10-17
收藏
得分:0 
cin.width(n);//n为整数也可以实现程序在读入约定个(n-1个)字符后不在读入,不过只能用于字符串
2008-10-21 22:49
快速回复:怎么样从程序出发来管理输入流,使程序在读入约定个字符后不在读入
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014461 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved