这是个怎样的世界啊
1103 缘分数、天长地久、2019数列、老鼠爱大米、String复读机、擅长C
#include<stdio.h>
#include<math.h>
int main() {
int left, right, flag=0;
scanf("%d%d", &left, &right);
for(int i=left; i<=right; i++) {
float temp = sqrt( pow(i,3) - pow(i-1,3) );
if( temp == (int)temp) {
for(int j=2; j<=sqrt(temp); j++) {
if( pow(j,2) + pow(j-1,2) == temp ) {
printf("%d %d\n", i, j);
flag = 1;
break;
}
}
}
}
if(!flag)
puts("No Solution");
return 0;
}
1104 天长地久
#include<stdio.h>
#include<math.h>
int GetGcd(int num1, int num2) {
int d = num1%num2;
while(d != 0) {
num1 = num2;
num2 = d;
d = num1%num2;
}
return num2;
}
int IsPrime(int num) {
if(num<2)
return 0;
for(int i=2; i<=sqrt(num); i++)
if(num%i == 0)
return 0;
return 1;
}
int DigitSum(int num) {
int sum = 0;
while(num != 0) {
sum += num%10;
num /= 10;
}
return sum;
}
int main() {
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++) {
int k, m, count9=1, flag=0;//k位数,各位数字和为m
scanf("%d%d", &k, &m);
printf("Case %d\n", i);
while(m-count9*9+1 > 0) {
if(IsPrime(GetGcd(m, m-count9*9+1)) && GetGcd(m, m-count9*9+1)>2) {
int n = m-count9*9+1;
for(int j=(int)pow(10,k-count9-1); j<=(pow)(10, k-count9); j++) {
if(DigitSum(j) == n) {
printf("%d %d\n", n, j*(int)pow(10, count9)-1);
flag = 1;
}
}
}
count9++;
}
if(!flag)
puts("No Solution");
}
return 0;
}
1106 2019数列
#include<stdio.h>
int DigitSum(int num) {//求数字的各位和
int sum = 0;
while(num > 0) {
sum += num%10;
num /= 10;
}
return sum;
}
int main() {
int n, num=2019;
scanf("%d", &n);
while(n-- > 0) {
printf("%d", num/1000);
num = num%1000*10 + DigitSum(num)%10;
}
return 0;
}
1107 老鼠爱大米
#include<stdio.h>
#define LEN 101
int main() {
int gCount, pCount, winner=-1, weight=-1;
scanf("%d%d", &gCount, &pCount);
for(int i=0; i<gCount; i++) {
for(int j=0; j<pCount; j++) {
int temp;
scanf("%d", &temp);
weight = temp>weight ? temp : weight;
}
printf("%d", weight);
if(i != gCount-1)
putchar(' ');
winner = weight>winner ? weight : winner;
weight = -1;
}
printf("\n%d", winner);
return 0;
}
1108 String复读机、擅长C
#include<stdio.h>
#include<string.h>
int main() {
int ch, flag, lCount[6] = {0};
char str[] = "String";
while((ch=getchar()) != '\n') {
int i = 0;
while(i<strlen(str) && str[i] != ch)
i++;
lCount[i] = i<strlen(str)? lCount[i]+1 : lCount[i];
}
do {
flag = 0;
for(int i=0; i<6; i++) {
if(lCount[i] != 0) {
printf("%c", str[i]);
lCount[i]--;
flag = 1;
}
}
} while(flag);
return 0;
}
1109 擅长C
#include<stdio.h>
#include<ctype.h>
#define LEN 500
int main() {
int ch, index=0, flag=0, wCount=0;
char letter[26][7][6]= {0}, words[LEN][11];
for(int i=0; i<26; i++) {
for(int j=0; j<7; j++)
scanf("%s", &letter[i][j]);
}
getchar();
for(int i=0; (ch=getchar())!='\n'; ) {
if(isupper(ch)) {
flag = 1;
words[i][index++]=ch;
} else if(flag == 1) { //上一次字符是大写字母
flag = 0;
words[i++][index] = '\0';
index = 0;
wCount++;
}
}
if(flag==1) {//若结束前的最后一个字符是大写字母则存最后一个单词。因为循环条件是 ch != '\n'
words[wCount][index] = '\0';
wCount++;
}
for(int i=0; i<wCount; i++) {//输出第i个单词
for(int row=0; row<7; row++) {//输出字母的第row行
for(int let=0; words[i][let]!='\0'; let++) {//输出单词第let个字母的第row行
printf("%s", letter[words[i][let]-'A'][row]);
if(words[i][let+1] != '\0')
putchar(' ');
}
putchar('\n');
}
if(i != wCount-1)
putchar('\n');
}
return 0;
}