这道c语言题怎么做

zjqcsh 2014-09-09 11:52:21
Description

冰冰最近刚学了一个好玩的游戏,并为之兴奋,于是他天天找人陪他玩游戏,这个游戏就是传说中的“石头剪刀布”。 游戏规则是,出拳之前双方齐喊口令“石头、剪子、布”(或其他口令),然后在话音刚落时同时出拳。握紧的拳头代表“石头”,食指和中指伸出代表“剪子”, 五指伸开代表“布”。“石头”胜“剪子”,“剪子”胜“布”,而“布”又胜过“石头”。若两人出的是一样的,则为平局。 现在问题来了,由于玩的盘数太多,从小不太擅长数数的的他无法计算出他总共胜了几场,平了几场,输了几场,请好心的你帮帮他吧!!!

Input

输入第一行包含一个整数n(0 < n <= 1000),表示他一共进行了几轮游戏。接下来n行每行有两个数字i,j(i表示冰冰出的拳,j表示他对手出的拳,若值为0则表示出的是石头,若值为1则 表示出的是剪刀,若值为2则表示出的是布。我们保证i,j的值是0到2之间的整数)。

Output

输出共有3行, 第一行输出一个整数表示冰冰一共赢了几轮的游戏; 第二行输出一个整数表示冰冰一共平了几轮的游戏; 第三行输出一个整数表示冰冰一共输了几轮的游戏。

Sample Input


3
0 1
0 0
0 2
Sample Output


1
1
1
Hint

以上输入输出样例中只有一组的测试数据

Source
...全文
169 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
熊熊大叔 2014-09-10
  • 打赏
  • 举报
回复
这么简单的题目,LZ你应该自己先试试,遇到有什么问题再问。
Falleyes 2014-09-10
  • 打赏
  • 举报
回复
//仅供参考:
#include<stdio.h>

int main(){
    int N;
    int a,b;
    int win=0,lose=0,draw=0;
    scanf("%d",&N);
    while(N--){
        scanf("%d%d",&a,&b);
        switch(a-b){
            case -1:++win;break;
            case 2:++win;break;
            case -2:++lose;break;
            case 1:++lose;break;
            case 0:++draw;break;
            default:break;
        }
    }
    printf("%d\n%d\n%d\n",win,draw,lose);
}
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n,i,j;
	int win = 0, fall = 0, flat = 0;
	printf("please input the num of the games: ");
	scanf("%d", &n);
	if( !(n >= 0 && n <= 1000) )
	{
		printf("please input the num 0 to 1000\n");
		exit(1);
	}
	
	while(n--)
	{
		printf("please input what the bingbing show: ");
		scanf("%d", &i);
		if( !(i >= 0 && i <= 2) )
		{
			printf("please input the num 0 to 2\n");
			exit(1);
		}
		
		printf("please input what the others show: ");
		scanf("%d", &j);
		if( !(j >= 0 && j <= 2) )
		{
			printf("please input the num 0 to 2\n");
			exit(1);
		}

		if(0 == i)
		{
			if(0 == j)
				flat++;
			else if (1 == j)
				win++;
			else
				fall++;
		}	
		else if(1 == i)
		{
			if(0 == j)
				fall++;
			else if (1 == j)
				flat++;
			else
				win++;
		}	
		else if(2 == i)
		{
			if(0 == j)
				win++;
			else if (1 == j)
				fall++;
			else
				flat++;
		}	
	}
	printf("The num of the win are  %d\n", win);
	printf("The num of the fall are  %d\n", fall);
	printf("The num of the flat are  %d\n", flat);
	
}
还可以把exit换成goto
百曉生 2014-09-10
  • 打赏
  • 举报
回复
楼主刚学C语言没多久?建议好好想想其中的逻辑,自己试试吧

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧