c语言电阻器分类代码实现

C语言实现电阻器的分类,朋友给的竞赛题目

QQ图片20160623225739.jpg




#include "stdio.h"
#include "string.h"
int main(){
	int n;
	scanf("%d",&n);
	int R[4]={0};// 0 =>film 1=>soli 2=>sens 3=>wire
	int i;
	int n0[n];
	char str[n][100];
	for(i=0;i<n;i++){
		scanf("%s %d",&str[i],&n0[i]);
		if(strstr(str[i],"wire_resistors")!=NULL)R[3]+=n0[i];
		if(strstr(str[i],"solid_resistors")!=NULL)R[1]+=n0[i];
		if(strstr(str[i],"film_resistors")!=NULL)R[0]+=n0[i];
		if(strstr(str[i],"sensitive_resistors")!=NULL)R[2]+=n0[i];
		
	}
		printf("FILM %d\n",R[0]);
		printf("SOLI %d\n",R[1]);
		printf("SENS %d\n",R[2]);
		printf("WIRE %d\n",R[3]);
	
	return 0;
}



相关推荐

发表评论

路人甲

网友评论(0)