L1-035 情人节
新知识
~是按位取反
scanf的返回值是输入值的个数
如果没有输入值就是返回-1
-1按位取反结果是0
while(~scanf("%d", &n))就是当没有输入的时候退出循环
思路
接触到了一个重来没有用过的方法
while(~scanf("%s",s)) 只要理解这句就很简单了
其中break,跳出while循环
源码
#include<stdio.h>
#include<string.h>
int main()
{
char s[11],a[11],b[11];
int n=0;
while(~scanf("%s",s))
{
if(s[0]=='.') break;
n++;
if(n==2) strcpy(a,s);
if(n==14) strcpy(b,s);
}
if(n<2) printf("Momo... No one is for you ...\n");
if(n>=2&&n<14) printf("%s is the only one for you...\n",a);
if(n>=14) printf("%s and %s are inviting you to dinner...\n",a,b);
}