《C语言程序设计》江宝钏主编-习题5-9-模拟登录!!!!

AC代码:

/*《C语言程序设计》江宝钏主编-习题5-9-模拟登录
Description 
编写程序模拟简单的密码登录,首先从键盘输入名字和密码,若密码正确则给出问候语。
若密码不正确,则给出错误提示,并允许再次输入,直到输入正确的密码或0结束。
用户名随意,不超过10个字节。
密码123456
Input 
用户名,和若干次密码。
Output 
若密码正确则输出:
Hello 用户名换行
并退出
若错误则输出:
Wrong Password!换行
并再次输入判断
若密码为0则在输出正确与否的结果后退出。

Sample Input Copy 
tom
123
123456
Sample Output Copy 
Wrong Password!
Hello tom
*/


//标程:
#include <stdio.h>
int main(void)
{
	char a[10];
	int s;
	scanf("%s",&a);
	while(1) 
	{
		getchar();
		scanf("%d",&s);
		if (s==123456)
		{
			printf("Hello %s\n",a);
			break;
		}
		else if (s==0)
		{
			printf("Wrong Password!");
			break;
		}
		else
		{
			printf("Wrong Password!\n");
		}
	}
	return 0;
}


/*C++代码:
#include <iostream>
#include <string>
using namespace std;       //千万别漏了这一句
int main(){
    string s;                //密码s
	char name[10];           //用户名限制10字节
    cin>>name;
    while(cin>>s){           //密码s是要循环输入的,用while(cin>>s)
        if(s=="123456"){
            cout<<"Hello "<<name<<endl;
            break;
        }else if(s=="0"){
            cout<<"Wrong Password!"<<endl;
            break;
        }else{
            cout<<"Wrong Password!"<<endl;
        }
    }
    return 0;
}
*/
发布了39 篇原创文章 · 获赞 7 · 访问量 3678

猜你喜欢

转载自blog.csdn.net/qq_45599068/article/details/104095460