满 山 红(WA)
查看原帖
满 山 红(WA)
303132
Okimoto楼主2020/6/22 13:44

菜鸡我又死在了橙题上。。。

Orz...

#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
string to_string(int n)
{
	int m = n;
	char s[100000];
    char ss[100000];
	int i=0,j=0;
	if (n < 0){
		m = 0 - m;
		j = 1;
		ss[0] = '-';
	}    
	while (m>0)
	{
		s[i++] = m % 10 + '0';
		m /= 10;
	}
	s[i] = '\0';
	i = i - 1;
	while (i >= 0)
	{
		ss[j++] = s[i--];
	}    
	ss[j] = '\0';    
	return ss;
}
int main(){
	int n;
	scanf("%d\n", &n);
	char in[n][10000];
	for(int i = 0; i < n; i ++){
		scanf("%[^\n]", in[i]);
		char w;
		scanf("\r\n");
	}
	for(int i = 0; i < n; i ++){
		char input[10000];
		strcpy(input, in[i]);
		if(input[0] <= '9' && input[0] >= '0'){
			int a = 0;
			int b = 0;
			int ptr = 0;
			while(input[ptr] != 32){
				a *= 10;
				a += input[ptr ++] - '0';
			}
			ptr ++;
			while(ptr < strlen(input)){
				b *= 10;
				b += input[ptr ++] - '0';
			}
			string output = "";
			output += to_string(a);
			output += "+";
			output += to_string(b);
			output += "=";
			output += to_string(a + b);
			printf("%s\n%d\n", output.c_str(), output.size());
		}
		else{
			char t = input[0];
			int ptr = 2;
			int a = 0;
			int b = 0;
			while(input[ptr] != 32){
				a *= 10;
				a += input[ptr ++] - '0';
			}
			ptr ++;
			while(ptr < strlen(input)){
				b *= 10;
				b += input[ptr ++] - '0';
			}
			string output = "";
			output += to_string(a);
			if(t == 'a'){
				output += "+";
			}else if(t == 'b'){
				output += "-";
			}else{
				output += "*";
			}
			output += to_string(b);
			output += "=";
			if(t == 'a'){
				output += to_string(a + b);
			}else if(t == 'b'){
				output += to_string(a - b);
			}else{
				output += to_string(a * b);
			}
			printf("%s\n%d\n", output.c_str(), output.size());
		}
	}
	return 0;
}
2020/6/22 13:44
加载中...