1 条题解

  • 0
    @ 2025-9-9 23:44:32

    C :

    #include <stdio.h>
    int main(void)
    {
    	char a[10],p[20];
    	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 name,pword;
    	getline(cin,name);
    	bool flag=false;
    	do
    	{
    		getline(cin,pword);
    		if (pword=="123456")
    		{
    			flag=true;
    			cout<<"Hello "<<name<<endl;
    			return 0;
    		}
    		else if (pword=="0")
    		{
    			cout<<"Wrong Password!"<<endl;
    			return 0;
    		}
    		else cout<<"Wrong Password!"<<endl;
    	} while (!flag);
    }
    
    • 1

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

    信息

    ID
    481
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者