ACM程序设计(一)

ACM程序设计(一)

1.1004

题目描述:Calculate a + b.a and b are integers. (0a, b≤1030).

输入:The input may contain several test cases.In each test case, 

there are two integers, a and b, separated by a space.

Input is terminated by EOF.

输出:For each test case, print out the sum of a and b.

样例输入

1234 5678
45 56
456129871123456789 789765412765432121

样例输出

6912
101
1245895283888888910
//************************1004***************************
#include
#include
#include
int main()
{
	char a[31],b[31],c[31],smallStr[31],bigStr[31];
	int small,big,temp,str1_len,str2_len,i,j,goHead=0,k;
	while(scanf("%s %s",a,b)!=EOF)
	{
		str1_len=strlen(a);//输入a的长度
		str2_len=strlen(b);//输入b的长度
		i=str1_len;
		j=str2_len;
		if(i>=j) 
		{
			small=j;
			big=i;
			for(i=0;i0;k--)
		{
			if(small>0)
			{
				temp=bigStr[k-1]-48+smallStr[small-1]-48+goHead;
				small--;
			}
			else
			{
				temp=bigStr[k-1]+goHead-48;
			}
			if(temp>=10)
			{
				goHead =1;
				c[k] = temp+38;
			}
			else
			{
				goHead=0;
				c[k] = temp+48;
			}
		}
		c[big+1]='\0';
		if(goHead==1)
			c[0]=49;
		else
		{
			for(i=0;i<=big;i++)
			{
				c[i]=c[i+1];
			}
		}
		printf("%s\n",c);
		goHead=0;
	}
}

2.1011

题目描述

A word defined as a string that contains only letters. Its length is defined as the string length. Two adjacent valid words are separated by spaces or (and) digits.

Write a program to figure out the longest word and its length in a one-line text. Suppose the text is shown by a string, comprised of letters, spaces and digits.

输入

Several strings, one string on each line (the number of characters on each line does not exceed 200). Each string is a test case (text). Input is terminated by EOF.

输出

For each test case, print out the longest word and its length with the format: word[space]:[space]length.

If there are n (n >= 2) words have the same longest length, print them with the format:

word1[space]:[space]length, [space]word2[space]:[space]length, [space]……, [space] wordn[space]:[space]length.

样例输入

Without such efforts the observers pointed out even such an accord would
not have been possible given the vastly different positions of the developed
and developing nations The world could hardly afford a no deal scenario
what with 119 global leaders attending the talks during the final stages

样例输出

observers : 9
different : 9, positions : 9, developed : 9
developing : 10
attending : 9

#include
#include
#include
int main()
{
	char line[200];
	char getN;
	int first[200];
	int length[200];
	int i,n,num1,j,k,num2;
	int tempf,templ,m,flag;
	while(scanf("%[^\n]",line)!=EOF)
	{
		gets(&getN);
		k=-1;m=1;n=0;
		memset(first,0,sizeof(first));
		memset(length,0,sizeof(length));
		//scanf("%[^\n]",line);
		num1=strlen(line);
		for(i=0;i


你可能感兴趣的:(Algorithms,C和C++,ACM)