[NWPU][2014][TRN][1]水题堆
7:30:00
开始用读入数字来解,比较复杂
//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 1100000;
const int INF = 2100000000;
int a, b;
int main()
{
//freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
while(~scanf("%d%d", &a, &b))
{
int ans = 0;
while(a != 0)
{
int t = a % 10;
a /= 10;
int m = b;
while(m != 0)
{
int temp = m % 10;
m /= 10;
ans += t * temp;
}
}
printf("%d\n", ans);
}
return 0;
}
后来发现用string类更简单,啊哈哈
//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 1100000;
const int INF = 2100000000;
string s1, s2;
int main()
{
freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
while(cin >> s1 >> s2)
{
int lens1 = s1.length();
int lens2 = s2.length();
int ans = 0;
for(int i = 0; i < lens1; i++)
{
for(int j = 0; j < lens2 ;j++)
{
ans += (s1[i] - '0') * (s2[j]- '0' );
}
}
printf("%d\n", ans);
}
return 0;
}