U E D R , A S I H C RSS

Code Race/2014.8.20/어르신과어린이

Difference between r1.1 and the current

@@ -1,3 +1,5 @@
윤석준, 김준석
{{{
// algorithm.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//


윤석준, 김준석

// algorithm.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char c[255];
int len;
int aa(char *c);
int isMinus(char c);
int _tmain(int argc, _TCHAR* argv[])
{

	FILE *f=fopen("input.txt","rt");
	int matrix[110][110];
	int i,j,max = -0x7fffffff;
	int mom=-0x7fffffff;
	int a,n,m;
	int flag = 0;

	fscanf(f,"%d %d",&n,&m);

	int k;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			memset(c,0,255);
			fscanf(f,"%s",&c);
			k=aa(c);
			matrix[i][j]=k;
		}
	}
	for(i=0;i<n;i++)
	{
		max=-0x7fffffff;
		for(j=0;j<m;j++)
		{
			if(matrix[i][j]>max) max=matrix[i][j];
		}
		printf("row %d: ",i+1);
		if(max==-0x7fffffff)
		{
			printf("NaN \n");
		}
		else
		{
			printf("%d\n",max);
			if(mom<max) mom=max;
		}
		
	}
	for(i=0;i<m;i++)
	{
		max=-0x7fffffff;
		for(j=0;j<n;j++)
		{
			if(matrix[j][i]>max) max=matrix[j][i];
		}
		printf("column %d: ",i+1);
		if(max==-0x7fffffff)
		{
			printf("NaN \n");
		}
		else
		{
			printf("%d\n",max);
			if(mom<max) mom=max;
		}
		
	}

	printf("matrix: ");
	if(mom==-0x7fffffff){
		printf("NaN\n");
	}
	else printf("%d\n", mom);

	return 0;
}
int aa(char *c)
{
	int flag=0,a;
	len = strlen(c);
	if(  (c[0]=='-' && len>=2) || c[0]>='0' && c[0]<='9' ) flag=0;
	else flag=1;
	
	for(int x=1;x<len;x++)
	{
		if(!( c[x] >= '0' && c[x] <= '9')){
				flag=1;
				break;
		}
	}

	if(flag==0) a=atoi(c);
	
	if(flag==0) return a;
	int bu;
	int sum1=0,sum2=0,x;
	int sw=0;

	if(c[0]=='-') sw=1;
	else if(isdigit(c[0]) ) sum1=0;
	else return -0x7fffffff;

	for(x=sw;x<len;x++)
	{
		if(!isdigit(c[x]))
		{
			if( c[x]=='-' ) bu=1;
			else if(c[x]=='+') bu=2;
			else if(c[x]=='*') bu=3;
			else bu=4;

			break;
		}
		sum1*=10;
		sum1+=c[x]-48;
	}
	if(bu==4) return -0x7fffffff;
	if(sw==1) sum1*=(-1);
	sw=x+1;
	int b=1;
	if(c[sw]=='-')
	{
		b=-1;
		sw=sw+1;
	}
	else if(isdigit(c[sw])) sum2=0;
	else return -0x7fffffff;
	for(x=sw;x<len;x++)
	{
		if(!isdigit(c[x]))
		{
			bu=4;
			break;
		}
		sum2*=10;
		sum2+=c[x]-48;
	}
	if(bu==4) return -0x7fffffff;
	sum2*=b;

	switch(bu)
	{
		case 1: return sum1-sum2; break;
		case 2: return sum1+sum2; break;
		case 3: return sum1*sum2; break;
	}
}



Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:55
Processing time 0.0407 sec